Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ASCIISet to lower execution time by ~10 to 30% #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

elliotwutingfeng
Copy link

Changes

  • Use ASCIISet, a zero dependency and zero heap allocation module for checking byte values, to reduce execution time by ~10 to 30% (see benchmarks below)

Benchmarks

Command

go test -bench . -benchmem -cpu 1

Before

goos: linux
goarch: amd64
pkg: github.com/iancoleman/strcase
cpu: AMD Ryzen 7 5800X 8-Core Processor             
BenchmarkToCamel                                 2112366               575.0 ns/op           128 B/op         10 allocs/op
BenchmarkToLowerCamel                            2861402               409.6 ns/op            96 B/op          7 allocs/op
BenchmarkToSnake                                  621049              1894 ns/op             480 B/op         30 allocs/op
BenchmarkToSnakeWithIgnore                        565810              2040 ns/op             408 B/op         20 allocs/op
BenchmarkToDelimited                              850269              1374 ns/op             304 B/op         19 allocs/op
BenchmarkToScreamingSnake                       20631154                59.00 ns/op           16 B/op          1 allocs/op
BenchmarkToKebab                                19712632                60.27 ns/op           16 B/op          1 allocs/op
BenchmarkToScreamingKebab                       20477086                58.17 ns/op           16 B/op          1 allocs/op
BenchmarkToScreamingDelimited                   20021593                58.48 ns/op           16 B/op          1 allocs/op
BenchmarkToScreamingDelimitedWithIgnore          8217859               145.8 ns/op            24 B/op          1 allocs/op
PASS
ok      github.com/iancoleman/strcase   13.300s

After

goos: linux
goarch: amd64
pkg: github.com/iancoleman/strcase
cpu: AMD Ryzen 7 5800X 8-Core Processor             
BenchmarkToCamel                                 2503086               483.8 ns/op           128 B/op         10 allocs/op
BenchmarkToLowerCamel                            3385527               351.1 ns/op            96 B/op          7 allocs/op
BenchmarkToSnake                                  708350              1663 ns/op             480 B/op         30 allocs/op
BenchmarkToSnakeWithIgnore                        676756              1627 ns/op             408 B/op         20 allocs/op
BenchmarkToDelimited                              908474              1136 ns/op             304 B/op         19 allocs/op
BenchmarkToScreamingSnake                       21560983                55.12 ns/op           16 B/op          1 allocs/op
BenchmarkToKebab                                22520330                52.71 ns/op           16 B/op          1 allocs/op
BenchmarkToScreamingKebab                       22808118                51.95 ns/op           16 B/op          1 allocs/op
BenchmarkToScreamingDelimited                   21881048                51.62 ns/op           16 B/op          1 allocs/op
BenchmarkToScreamingDelimitedWithIgnore         11011074               105.1 ns/op            24 B/op          1 allocs/op
PASS
ok      github.com/iancoleman/strcase   12.786s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant