Skip to content

Add a benchmark of atomic increments #25

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

Merged
merged 1 commit into from
Jul 6, 2024
Merged

Add a benchmark of atomic increments #25

merged 1 commit into from
Jul 6, 2024

Conversation

polytypic
Copy link
Collaborator

@polytypic polytypic commented Jul 5, 2024

This adds a benchmark of incrementing a int Atomic.t using Atomic.incr and Atomic.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.

@polytypic polytypic force-pushed the add-incr-bench branch 3 times, most recently from 35c09de to 1698a49 Compare July 5, 2024 23:36
@polytypic polytypic merged commit e041b01 into main Jul 6, 2024
6 checks passed
@polytypic polytypic deleted the add-incr-bench branch July 6, 2024 09:24
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