Add a benchmark of atomic increments #25
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a benchmark of incrementing a
int Atomic.t
usingAtomic.incr
andAtomic.compare_and_set
with and without randomized exponential backoff.This benchmark is highly CPU dependent. Here are results from a run my M3 Max with OCaml 5.2:
➜ multicore-bench git:(add-incr-bench) dune exec --release -- bench/main.exe -budget 1 -brief incr Atomic incr: time per op/CAS, 1 domains: 4.89 ns ops over time/CAS, 1 domains: 204.47 M/s time per op/CAS, 2 domains: 34.43 ns ops over time/CAS, 2 domains: 58.09 M/s time per op/CAS, 4 domains: 160.78 ns ops over time/CAS, 4 domains: 24.88 M/s time per op/CAS, 8 domains: 1267.91 ns ops over time/CAS, 8 domains: 6.33 M/s time per op/CAS with backoff, 1 domains: 4.86 ns ops over time/CAS with backoff, 1 domains: 205.77 M/s time per op/CAS with backoff, 2 domains: 10.09 ns ops over time/CAS with backoff, 2 domains: 198.26 M/s time per op/CAS with backoff, 4 domains: 22.73 ns ops over time/CAS with backoff, 4 domains: 176.00 M/s time per op/CAS with backoff, 8 domains: 55.53 ns ops over time/CAS with backoff, 8 domains: 144.06 M/s time per op/Incr, 1 domains: 1.90 ns ops over time/Incr, 1 domains: 527.59 M/s time per op/Incr, 2 domains: 11.38 ns ops over time/Incr, 2 domains: 175.74 M/s time per op/Incr, 4 domains: 40.06 ns ops over time/Incr, 4 domains: 99.84 M/s time per op/Incr, 8 domains: 349.91 ns ops over time/Incr, 8 domains: 22.86 M/s
It is particularly interesting that
Atomic.incr
seems to suffer more from contentention on M3 Max with OCaml 5.2 than CAS with backoff.