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

Add a minimalist Unix IO benchmark #17

Merged
merged 1 commit into from
Apr 9, 2024
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
32 changes: 32 additions & 0 deletions bench/bench_unix.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
open Multicore_bench

let run_one ~budgetf ~n_domains () =
let n_bytes = 65536 in

let init _ =
let inn, out = Unix.pipe ~cloexec:true () in
(inn, out, Bytes.create 1)
in
let work _ (inn, out, byte) =
let n = Unix.write out (Bytes.create n_bytes) 0 n_bytes in
assert (n = n_bytes);
for _ = 1 to n_bytes do
let n : int = Unix.read inn byte 0 1 in
assert (n = 1)
done;
Unix.close inn;
Unix.close out
in

let config =
Printf.sprintf "%d worker%s" n_domains (if n_domains = 1 then "" else "s")
in
Times.record ~budgetf ~n_domains ~n_warmups:1 ~n_runs_min:1 ~init ~work ()
|> Times.to_thruput_metrics ~n:(n_bytes * n_domains) ~singular:"blocking read"
~config

let run_suite ~budgetf =
[ 1; 2; 4 ]
|> List.concat_map @@ fun n_domains ->
if Sys.win32 || Domain.recommended_domain_count () < n_domains then []
else run_one ~budgetf ~n_domains ()
1 change: 1 addition & 0 deletions bench/dune
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let () =
(libraries
multicore-bench
backoff
unix
multicore-magic |}
^ maybe_domain_shims_and_threads ^ {| ))
|}
1 change: 1 addition & 0 deletions bench/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let benchmarks =
("Atomic", Bench_atomic.run_suite);
("Queue", Bench_queue.run_suite);
("Stack", Bench_stack.run_suite);
("Unix", Bench_unix.run_suite);
]

let () = Multicore_bench.Cmd.run ~benchmarks ()
Loading