package main
import (
"fmt"
"log"
"strings"
"time"
)
func main() {
str := "sum::goods_num"
var content,content1 string
var i int
start1 := time.Now()
for i = 0;i<1000000;i++ {
content = str[5 : ]
}
elapsed := time.Since(start1)
fmt.Println(elapsed)
log.Println(content)
start2 := time.Now()
for i = 0;i<1000000;i++ {
selectStruct := strings.Split(str, "::")
if len(selectStruct) != 2 {
log.Println("select format error")
}
content1 = selectStruct[1]
}
elapsed1 := time.Since(start2)
fmt.Println(elapsed1)
log.Println(content1)
}
性能对比如下:
558.996µs
2019/07/30 10:49:16 goods_num
118.718357ms
2019/07/30 10:49:16 goods_num
Process finished with exit code 0
有疑问加站长微信联系(非本文作者)