Skip to content
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

Ignore results from ops on ref benchmarks #35

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ocaml/opam:debian-ocaml-5.3
WORKDIR /bench-dir
RUN sudo ln -sf /usr/bin/opam-2.1 /usr/bin/opam
WORKDIR bench-dir
RUN sudo chown opam .
COPY *.opam ./
RUN opam remote add origin https://github.com/ocaml/opam-repository.git && \
Expand Down
16 changes: 7 additions & 9 deletions bench/bench_atomic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module Atomic = struct
modify ~backoff:(Backoff.once backoff) x f
end

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

let run_one ~budgetf ?(n_iter = 500 * Util.iter_factor)
(Op (name, extra, value, op1, op2)) =
Expand All @@ -23,8 +22,8 @@ let run_one ~budgetf ?(n_iter = 500 * Util.iter_factor)
let work _ () =
let rec loop i =
if i > 0 then begin
op1 loc;
op2 loc;
op1 loc |> ignore;
op2 loc |> ignore;
loop (i - 2)
end
in
Expand All @@ -36,18 +35,17 @@ let run_one ~budgetf ?(n_iter = 500 * Util.iter_factor)

let run_suite ~budgetf =
[
(let get x = Atomic.get x |> ignore in
(let get x = Atomic.get x in
Op ("get", 10, 42, get, get));
(let incr x = Atomic.incr x in
Op ("incr", 1, 0, incr, incr));
(let push x = Atomic.modify x (fun xs -> 101 :: xs)
and pop x = Atomic.modify x (function [] -> [] | _ :: xs -> xs) in
Op ("push & pop", 2, [], push, pop));
(let cas01 x = Atomic.compare_and_set x 0 1 |> ignore
and cas10 x = Atomic.compare_and_set x 1 0 |> ignore in
(let cas01 x = Atomic.compare_and_set x 0 1
and cas10 x = Atomic.compare_and_set x 1 0 in
Op ("cas int", 1, 0, cas01, cas10));
(let xchg1 x = Atomic.exchange x 1 |> ignore
and xchg0 x = Atomic.exchange x 0 |> ignore in
(let xchg1 x = Atomic.exchange x 1 and xchg0 x = Atomic.exchange x 0 in
Op ("xchg int", 1, 0, xchg1, xchg0));
(let swap x = Atomic.modify x (fun (x, y) -> (y, x)) in
Op ("swap", 2, (4, 2), swap, swap));
Expand Down
15 changes: 7 additions & 8 deletions bench/bench_ref.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Ref = struct
modify ~backoff:(Backoff.once backoff) x f
end

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

let run_one ~budgetf ?(n_iter = 500 * Util.iter_factor)
(Op (name, extra, value, op1, op2)) =
Expand All @@ -38,8 +38,8 @@ let run_one ~budgetf ?(n_iter = 500 * Util.iter_factor)
let work _ () =
let rec loop i =
if i > 0 then begin
op1 loc;
op2 loc;
op1 loc |> ignore;
op2 loc |> ignore;
loop (i - 2)
end
in
Expand All @@ -51,18 +51,17 @@ let run_one ~budgetf ?(n_iter = 500 * Util.iter_factor)

let run_suite ~budgetf =
[
(let get x = Ref.get x |> ignore in
(let get x = Ref.get x in
Op ("get", 10, 42, get, get));
(let incr x = Ref.incr x in
Op ("incr", 1, 0, incr, incr));
(let push x = Ref.modify x (fun xs -> 101 :: xs)
and pop x = Ref.modify x (function [] -> [] | _ :: xs -> xs) in
Op ("push & pop", 2, [], 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", 1, 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", 1, 0, xchg1, xchg0));
(let swap x = Ref.modify x (fun (x, y) -> (y, x)) in
Op ("swap", 2, (4, 2), swap, swap));
Expand Down
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
Loading