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

Bitwise math for speed #11

Merged
merged 1 commit into from
Aug 3, 2016
Merged

Bitwise math for speed #11

merged 1 commit into from
Aug 3, 2016

Conversation

gammazero
Copy link
Contributor

No description provided.

@gammazero
Copy link
Contributor Author

gammazero commented Aug 3, 2016

Without modular math

> go test -bench .
PASS
BenchmarkQueueSerial-8      10000000           317 ns/op
BenchmarkQueueGet-8         100000000           13.8 ns/op
BenchmarkQueueTickTock-8    50000000            29.6 ns/op

With modular math

> go test -bench .
PASS
BenchmarkQueueSerial-8      10000000           311 ns/op
BenchmarkQueueGet-8         300000000            5.05 ns/op
BenchmarkQueueTickTock-8    100000000           12.9 ns/op

Results were consistent across a number of runs for both.

While the optimizer can optimize multiplication by powers of 2, it probably cannot optimize to do bitwise modulus because it does not know apriori if it is operating on numbers that are powers of 2.

@eapache
Copy link
Owner

eapache commented Aug 3, 2016

Thanks!

@eapache eapache merged commit f0262ae into eapache:master Aug 3, 2016
@gammazero gammazero deleted the bitmath branch August 3, 2016 21:10
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.

2 participants