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

util: speed up failure path of ByteToBase10 #505

Merged
merged 1 commit into from
Nov 24, 2014
Merged

Conversation

iand
Copy link
Contributor

@iand iand commented Nov 24, 2014

ready for review

The failure path for ByteToBase10 was not breaking out of the loop so the entire byte slice would still be scanned even if the first byte gave an error. Additonally a failure would allocate to create a new error.

Benchmark before:

BenchmarkByteToBase10Valid  100000000         20.8 ns/op         0 B/op      0 allocs/op
BenchmarkByteToBase10Invalid    20000000          81.3 ns/op        16 B/op      1 allocs/op

Benchmark after:

BenchmarkByteToBase10Valid  100000000         14.8 ns/op         0 B/op      0 allocs/op
BenchmarkByteToBase10Invalid    300000000          4.68 ns/op        0 B/op      0 allocs/op

@mreiferson
Copy link
Member

sweet, thanks!

mreiferson added a commit that referenced this pull request Nov 24, 2014
util: speed up failure path of ByteToBase10
@mreiferson mreiferson merged commit f7da860 into nsqio:master Nov 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants