Skip to content

Commit 2a653b6

Browse files
committed
Benchmark queues and stacks with heap allocated blocks
Queues and stacks were previously benchmarked with immediate values only, which unfortunately partially hides the potential cost of write barriers related to setting and clearing elements. Partially hiding the cost of write barriers makes the queue benchmarks unrealistic. Queues and stack are very rarely used with only immediate values.
1 parent db81288 commit 2a653b6

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

bench/bench_bounded_queue.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Make (Bounded_queue : Bounded_queue_intf.BOUNDED_QUEUE) : BENCH = struct
99
let t = Bounded_queue.create () in
1010

1111
let op push =
12-
if push then Bounded_queue.try_push t 101 |> ignore
12+
if push then Bounded_queue.try_push t (ref push) |> ignore
1313
else Bounded_queue.pop_opt t |> ignore
1414
in
1515

@@ -43,7 +43,7 @@ module Make (Bounded_queue : Bounded_queue_intf.BOUNDED_QUEUE) : BENCH = struct
4343
let n = Util.alloc n_msgs_to_add in
4444
if 0 < n then begin
4545
for i = 1 to n do
46-
Bounded_queue.try_push t i |> ignore
46+
Bounded_queue.try_push t (ref i) |> ignore
4747
done;
4848
work ()
4949
end

bench/bench_bounded_stack.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ let run_one_domain ~budgetf ?(n_msgs = 50 * Util.iter_factor) () =
55
let t = Stack.create () in
66

77
let op push =
8-
if push then Stack.try_push t 101 |> ignore else Stack.pop_opt t |> ignore
8+
if push then Stack.try_push t (ref push) |> ignore
9+
else Stack.pop_opt t |> ignore
910
in
1011

1112
let init _ =
@@ -37,7 +38,7 @@ let run_one ~budgetf ?(n_adders = 2) ?(n_takers = 2)
3738
let n = Util.alloc n_msgs_to_add in
3839
if 0 < n then begin
3940
for i = 1 to n do
40-
Stack.try_push t i |> ignore
41+
Stack.try_push t (ref i) |> ignore
4142
done;
4243
work ()
4344
end

bench/bench_mpsc.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Queue = Saturn.Single_consumer_queue
44
let run_one_domain ~budgetf ?(n_msgs = 50 * Util.iter_factor) () =
55
let t = Queue.create () in
66

7-
let op push = if push then Queue.push t 101 else Queue.pop_opt t |> ignore in
7+
let op push =
8+
if push then Queue.push t (ref push) else Queue.pop_opt t |> ignore
9+
in
810

911
let init _ =
1012
assert (Queue.is_empty t);
@@ -35,7 +37,7 @@ let run_one ~budgetf ?(n_adders = 2) ?(n_takers = 2)
3537
let n = Util.alloc n_msgs_to_add in
3638
if 0 < n then begin
3739
for i = 1 to n do
38-
Queue.push t i
40+
Queue.push t (ref i)
3941
done;
4042
work ()
4143
end

bench/bench_queue.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Make (Queue : Michael_scott_queue_intf.MS_QUEUE) : BENCH = struct
99
let t = Queue.create () in
1010

1111
let op push =
12-
if push then Queue.push t 101 else Queue.pop_opt t |> ignore
12+
if push then Queue.push t (ref push) else Queue.pop_opt t |> ignore
1313
in
1414

1515
let init _ =
@@ -42,7 +42,7 @@ module Make (Queue : Michael_scott_queue_intf.MS_QUEUE) : BENCH = struct
4242
let n = Util.alloc n_msgs_to_add in
4343
if 0 < n then begin
4444
for i = 1 to n do
45-
Queue.push t i
45+
Queue.push t (ref i)
4646
done;
4747
work ()
4848
end

bench/bench_spsc_queue.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ module Make (Queue : Spsc_queue_intf.SPSC_queue) : BENCH = struct
1717
done;
1818
let n = Random.int ((1 lsl size_exponent) + 1) in
1919
for i = 1 to n do
20-
Queue.push_exn t i
20+
Queue.push_exn t (ref i)
2121
done
2222
in
2323
let work i () =
2424
if i = 0 then
2525
let rec loop n =
2626
if 0 < n then
27-
if Queue.try_push t n then loop (n - 1)
27+
if Queue.try_push t (ref n) then loop (n - 1)
2828
else begin
2929
Domain.cpu_relax ();
3030
loop n

bench/bench_stack.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Stack = Saturn.Stack
44
let run_one_domain ~budgetf ?(n_msgs = 50 * Util.iter_factor) () =
55
let t = Stack.create () in
66

7-
let op push = if push then Stack.push t 101 else Stack.pop_opt t |> ignore in
7+
let op push =
8+
if push then Stack.push t (ref push) else Stack.pop_opt t |> ignore
9+
in
810

911
let init _ =
1012
assert (Stack.is_empty t);
@@ -35,7 +37,7 @@ let run_one ~budgetf ?(n_adders = 2) ?(n_takers = 2)
3537
let n = Util.alloc n_msgs_to_add in
3638
if 0 < n then begin
3739
for i = 1 to n do
38-
Stack.push t i
40+
Stack.push t (ref i)
3941
done;
4042
work ()
4143
end

bench/bench_ws_deque.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ let run_as_one_domain ~budgetf ?(n_msgs = 150 * Util.iter_factor) order =
8989
let t = Ws_deque.create () in
9090

9191
let op_lifo push =
92-
if push then Ws_deque.push t 101
92+
if push then Ws_deque.push t (ref push)
9393
else
9494
match Ws_deque.pop_exn t with _ -> () | exception Ws_deque.Empty -> ()
9595
and op_fifo push =
96-
if push then Ws_deque.push t 101
96+
if push then Ws_deque.push t (ref push)
9797
else
9898
match Ws_deque.steal_exn t with _ -> () | exception Ws_deque.Empty -> ()
9999
in
@@ -151,7 +151,7 @@ let run_as_spmc ~budgetf ~n_thiefs () =
151151
work ()
152152
else
153153
for i = 1 to n_msgs do
154-
Ws_deque.push t i
154+
Ws_deque.push t (ref i)
155155
done
156156
in
157157

0 commit comments

Comments
 (0)