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

Feat/fast modulo #1

Merged
merged 4 commits into from Dec 1, 2019
Merged

Feat/fast modulo #1

merged 4 commits into from Dec 1, 2019

Conversation

@sevagh
Copy link
Owner

sevagh commented Dec 1, 2019

By using the fastdiv library (https://github.com/bmkessler/fastdiv, based on https://github.com/lemire/fastmod), I can support arbitrary ringbuffer sizes without the expensive modulo (currently I enforce power-of-two to use the a & (b - 1) trick).

Benchmarks:

sevagh:ringbuffer1 $ benchcmp old.txt fastdiv.txt
benchmark                                        old ns/op       new ns/op       delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     41697812531     47722719778     +14.45%

benchmark                                        old allocs     new allocs     delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     2              4              +100.00%

benchmark                                        old bytes     new bytes     delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     96            520           +441.67%
sevagh:ringbuffer1 $
sevagh:ringbuffer1 $ benchcmp old.txt regular_modulo.txt
benchmark                                        old ns/op       new ns/op       delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     41697812531     66041473288     +58.38%

benchmark                                        old allocs     new allocs     delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     2              2              +0.00%

benchmark                                        old bytes     new bytes     delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     96            96            +0.00%
sevagh:ringbuffer1 $
sevagh:ringbuffer1 $ benchcmp regular_modulo.txt fastdiv.txt
benchmark                                        old ns/op       new ns/op       delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     66041473288     47722719778     -27.74%

benchmark                                        old allocs     new allocs     delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     2              4              +100.00%

benchmark                                        old bytes     new bytes     delta
BenchmarkManyRingbuffersBillionsOfIntegers-8     96            520           +441.67%
sevagh added 4 commits Dec 1, 2019
@sevagh sevagh merged commit 51385df into master Dec 1, 2019
@sevagh sevagh deleted the feat/fast-modulo branch Dec 1, 2019
@sevagh sevagh restored the feat/fast-modulo branch Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.