Skip to content

Commit 0386004

Browse files
committed
Add minimalistic Accumulator benchmark
1 parent ce34db0 commit 0386004

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

bench/bench_accumulator.ml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
open Kcas_data
2+
open Bench
3+
4+
let run_one ~n_domains ?(factor = 1) ?(n_ops = 60 * factor * Util.iter_factor)
5+
() =
6+
let t = Accumulator.make 0 in
7+
8+
let n_ops_todo = Atomic.make n_ops |> Multicore_magic.copy_as_padded in
9+
10+
let init _ = () in
11+
12+
let work _ () =
13+
let rec work () =
14+
let n = Util.alloc n_ops_todo in
15+
if n <> 0 then
16+
let rec loop n =
17+
if 0 < n then begin
18+
Accumulator.incr t;
19+
Accumulator.decr t;
20+
loop (n - 2)
21+
end
22+
else work ()
23+
in
24+
loop n
25+
in
26+
work ()
27+
in
28+
29+
let after () = Atomic.set n_ops_todo n_ops in
30+
31+
let times = Times.record ~n_domains ~init ~work ~after () in
32+
33+
let name metric =
34+
Printf.sprintf "%s/%d worker%s, 0%% reads" metric n_domains
35+
(if n_domains = 1 then "" else "s")
36+
in
37+
38+
List.concat
39+
[
40+
Stats.of_times times
41+
|> Stats.scale (1_000_000_000.0 /. Float.of_int n_ops)
42+
|> Stats.to_json
43+
~name:(name "time per operation")
44+
~description:"Average time to increment accumulator" ~units:"ns";
45+
Times.invert times |> Stats.of_times
46+
|> Stats.scale (Float.of_int (n_ops * n_domains) /. 1_000_000.0)
47+
|> Stats.to_json
48+
~name:(name "operations over time")
49+
~description:
50+
"Number of operations performed over time using all domains"
51+
~units:"M/s";
52+
]
53+
54+
let run_suite ~factor =
55+
[ 1; 2; 4 ]
56+
|> List.concat_map @@ fun n_domains -> run_one ~n_domains ~factor ()

bench/main.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let benchmarks =
33
("Kcas Loc", Bench_loc.run_suite);
44
("Kcas Xt", Bench_xt.run_suite);
55
("Kcas parallel CMP", Bench_parallel_cmp.run_suite);
6+
("Kcas_data Accumulator", Bench_accumulator.run_suite);
67
("Kcas_data Hashtbl", Bench_hashtbl.run_suite);
78
("Kcas_data Mvar", Bench_mvar.run_suite);
89
("Kcas_data Queue", Bench_queue.run_suite);

0 commit comments

Comments
 (0)