Skip to content

Commit

Permalink
Add a minimalist Unix IO benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
polytypic committed Apr 9, 2024
1 parent 497782e commit b79ac03
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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 ()

0 comments on commit b79ac03

Please sign in to comment.