From d7441e3cf9517280c074025f0689b77ef50b020b Mon Sep 17 00:00:00 2001 From: Vesa Karvonen Date: Wed, 20 Dec 2023 23:31:55 +0200 Subject: [PATCH] Add `Loc.incr` benchmark --- bench/bench_loc.ml | 32 ++++++++++++++++++++++++++++++++ bench/main.ml | 1 + 2 files changed, 33 insertions(+) create mode 100644 bench/bench_loc.ml diff --git a/bench/bench_loc.ml b/bench/bench_loc.ml new file mode 100644 index 00000000..7ccaf137 --- /dev/null +++ b/bench/bench_loc.ml @@ -0,0 +1,32 @@ +open Kcas +open Bench + +let run_one ?(factor = 1) ?(n_iter = 25 * factor * Util.iter_factor) () = + let loc = Loc.make 0 in + + let init _ = () in + let work _ () = + let rec loop i = + if i > 0 then begin + Loc.incr loc; + loop (i - 1) + end + in + loop n_iter + in + + let times = Times.record ~n_domains:1 ~init ~work () in + + List.concat + [ + Stats.of_times times + |> Stats.scale (1_000_000_000.0 /. Float.of_int n_iter) + |> Stats.to_json ~name:"time per op/incr" + ~description:"Time to perform a single op" ~units:"ns"; + Times.invert times |> Stats.of_times + |> Stats.scale (Float.of_int n_iter /. 1_000_000.0) + |> Stats.to_json ~name:"ops over time/incr" + ~description:"Number of operations performed over time" ~units:"M/s"; + ] + +let run_suite ~factor = run_one ~factor () diff --git a/bench/main.ml b/bench/main.ml index eee7685a..baa9222f 100644 --- a/bench/main.ml +++ b/bench/main.ml @@ -1,5 +1,6 @@ let benchmarks = [ + ("Kcas Loc", Bench_loc.run_suite); ("Kcas Op", Bench_op.run_suite); ("Kcas Xt", Bench_xt.run_suite); ("Kcas parallel CMP", Bench_parallel_cmp.run_suite);