Skip to content

Commit

Permalink
Allow selecting a benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
talex5 committed May 30, 2023
1 parent a9de663 commit 5bbe6da
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ all:
dune build @runtest @all

bench:
dune exec -- ./bench/bench_main.exe
dune exec -- ./bench/main.exe

test_posix:
EIO_BACKEND=posix dune runtest
Expand Down
25 changes: 0 additions & 25 deletions bench/bench_main.ml

This file was deleted.

2 changes: 1 addition & 1 deletion bench/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executables
(names bench_main)
(names main)
(libraries eio_main yojson))
43 changes: 43 additions & 0 deletions bench/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let benchmarks = [
"buf", Bench_buf_read.run;
"cancel", Bench_cancel.run;
"fd", Bench_fd.run;
"condition", Bench_condition.run;
"yield", Bench_yield.run;
"mutex", Bench_mutex.run;
"semaphore", Bench_semaphore.run;
"stream", Bench_stream.run;
"promise", Bench_promise.run;
"http", Bench_http.run;
]

let usage_error () =
let names = List.map fst benchmarks in
Fmt.epr "Usage: main.exe [%a]@." Fmt.(list ~sep:(any " | ") string) names;
exit 1

let () =
Eio_main.run @@ fun env ->
let benchmarks =
match Array.to_list Sys.argv with
| [_] -> benchmarks
| [_; name] ->
begin match List.assoc_opt name benchmarks with
| Some run -> [name, run]
| None ->
Fmt.epr "Unknown benchmark %S@." name;
usage_error ()
end
| _ -> usage_error ()
in
let run (name, fn) =
Eio.traceln "Running %s..." name;
let metrics = fn env in
`Assoc [
"name", `String name;
"metrics", `List (List.map Metric.to_json metrics);
]
in
Fmt.pr "%a@." (Yojson.Safe.pretty_print ~std:true) @@ `Assoc [
"results", `List (List.map run benchmarks);
]

0 comments on commit 5bbe6da

Please sign in to comment.