Skip to content

扩展exstrings函数#9

Merged
thinkeridea merged 3 commits intomasterfrom
exstrings
Oct 28, 2019
Merged

扩展exstrings函数#9
thinkeridea merged 3 commits intomasterfrom
exstrings

Conversation

@thinkeridea
Copy link
Copy Markdown
Owner

  • 优化 exstrings.Reverse 方法,使其代码更加易读,并进行多种反转字符串方法性能对比,其测试代码在exstrings/benchmark/reverse_test.go, 其中BenchmarkReverseUTF8DecodeRuneInString 是优化前版本, BenchmarkExstringsReverse 是优化有版本,性能提升约3%,其结果如下:
$ 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),相比 []byte(s) 转换类型提升 14%,这仅仅是一个趣味函数,性能测试代码exstrings/benchmark/convert_test.go 结果如下:
$ 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

@thinkeridea thinkeridea added enhancement New feature or request optimize Promote or improve code functionality and performance labels Oct 28, 2019
@thinkeridea thinkeridea merged commit 42512d1 into master Oct 28, 2019
@thinkeridea thinkeridea deleted the exstrings branch October 28, 2019 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request optimize Promote or improve code functionality and performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant