Closed thinkeridea closed 4 years ago
BenchmarkReverseUTF8DecodeRuneInString
BenchmarkExstringsReverse
$ go test -benchmem -bench="Reverse" goos: darwin goarch: amd64 pkg: github.com/thinkeridea/go-extend/exstrings/benchmark BenchmarkReverseRunes-8 703830 1700 ns/op 480 B/op 2 allocs/op BenchmarkReverseRange-8 1400299 861 ns/op 192 B/op 1 allocs/op BenchmarkReverseUTF8DecodeRuneInString-8 1482175 717 ns/op 192 B/op 1 allocs/op BenchmarkExstringsReverse-8 1698225 694 ns/op 192 B/op 1 allocs/op PASS ok github.com/thinkeridea/go-extend/exstrings/benchmark 7.995s
exstrings.Bytes
[]byte(s)
$ go test -benchmem -bench="StringToBytes" goos: darwin goarch: amd64 pkg: github.com/thinkeridea/go-extend/exstrings/benchmark BenchmarkStandardLibraryStringToBytes-8 19118637 64.0 ns/op 192 B/op 1 allocs/op BenchmarkExstringsStringToBytes-8 22079703 55.1 ns/op 192 B/op 1 allocs/op PASS ok github.com/thinkeridea/go-extend/exstrings/benchmark 4.426s
exutf8.RuneSub
exbytes.Sub
exutf8.RuneSubString
exstrings.SubString
BenchmarkReverseUTF8DecodeRuneInString
是优化前版本,BenchmarkExstringsReverse
是优化有版本,性能提升约3%,其结果如下:exstrings.Bytes
方法,用来替换[]byte(s)
,相比[]byte(s)
转换类型提升 14%,这仅仅是一个趣味函数,性能测试代码exstrings/benchmark/convert_test.go 结果如下:exutf8.RuneSub
别名exbytes.Sub
exutf8.RuneSubString
别名exstrings.SubString