Skip to content

Commit

Permalink
Ignore results from ops on ref benchmark
Browse files Browse the repository at this point in the history
This prevents the `get` op from being optimized away and makes some other
operations also more realistic.
  • Loading branch information
polytypic committed Jan 21, 2025
1 parent c4f3be5 commit f07ff29
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions bench/bench_ref_mutex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Ref = struct
before
end

type t = Op : string * 'a * ('a Ref.t -> unit) * ('a Ref.t -> unit) -> t
type t = Op : string * 'a * ('a Ref.t -> _) * ('a Ref.t -> _) -> t

(** For some reason allocating the mutex inside [run_one] tends to cause
performance hiccups, i.e. some operations appear to be 10x slower than
Expand All @@ -34,10 +34,10 @@ let run_one ~budgetf ?(n_iter = 250 * Util.iter_factor)
let rec loop i =
if i > 0 then begin
Mutex.lock mutex;
op1 loc;
op1 loc |> ignore;
Mutex.unlock mutex;
Mutex.lock mutex;
op2 loc;
op2 loc |> ignore;
Mutex.unlock mutex;
loop (i - 2)
end
Expand All @@ -50,18 +50,17 @@ let run_one ~budgetf ?(n_iter = 250 * Util.iter_factor)

let run_suite ~budgetf =
[
(let get x = !x |> ignore in
(let get x = !x in
Op ("get", 42, get, get));
(let incr x = x := !x + 1 in
Op ("incr", 0, incr, incr));
(let push x = x := 101 :: !x
and pop x = match !x with [] -> () | _ :: xs -> x := xs in
Op ("push & pop", [], push, pop));
(let cas01 x = Ref.compare_and_set x 0 1 |> ignore
and cas10 x = Ref.compare_and_set x 1 0 |> ignore in
(let cas01 x = Ref.compare_and_set x 0 1
and cas10 x = Ref.compare_and_set x 1 0 in
Op ("cas int", 0, cas01, cas10));
(let xchg1 x = Ref.exchange x 1 |> ignore
and xchg0 x = Ref.exchange x 0 |> ignore in
(let xchg1 x = Ref.exchange x 1 and xchg0 x = Ref.exchange x 0 in
Op ("xchg int", 0, xchg1, xchg0));
(let swap x =
let l, r = !x in
Expand Down

0 comments on commit f07ff29

Please sign in to comment.