mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-07 18:37:56 -05:00
add basic benchmark to exercize trace-tef
This commit is contained in:
parent
f3ae3397de
commit
e20028e3f9
3 changed files with 43 additions and 0 deletions
4
bench/dune
Normal file
4
bench/dune
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
(executable
|
||||||
|
(name trace1)
|
||||||
|
(libraries trace.core trace-tef))
|
||||||
36
bench/trace1.ml
Normal file
36
bench/trace1.ml
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
module Trace = Trace_core
|
||||||
|
|
||||||
|
let ( let@ ) = ( @@ )
|
||||||
|
|
||||||
|
let work ~n () : unit =
|
||||||
|
for _i = 1 to n do
|
||||||
|
let@ _sp =
|
||||||
|
Trace.with_span ~__FILE__ ~__LINE__ "outer" ~data:(fun () ->
|
||||||
|
[ "i", `Int _i ])
|
||||||
|
in
|
||||||
|
for _k = 1 to 10 do
|
||||||
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "inner" in
|
||||||
|
()
|
||||||
|
done;
|
||||||
|
Thread.delay 1e-6
|
||||||
|
done
|
||||||
|
|
||||||
|
let main ~n ~j () : unit =
|
||||||
|
let domains = Array.init j (fun _ -> Domain.spawn (fun () -> work ~n ())) in
|
||||||
|
Array.iter Domain.join domains
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let@ () = Trace_tef.with_setup () in
|
||||||
|
|
||||||
|
let n = ref 10_000 in
|
||||||
|
let j = ref 4 in
|
||||||
|
|
||||||
|
let args =
|
||||||
|
[
|
||||||
|
"-n", Arg.Set_int n, " number of iterations";
|
||||||
|
"-j", Arg.Set_int j, " set number of workers";
|
||||||
|
]
|
||||||
|
|> Arg.align
|
||||||
|
in
|
||||||
|
Arg.parse args ignore "bench1";
|
||||||
|
main ~n:!n ~j:!j ()
|
||||||
3
bench1.sh
Executable file
3
bench1.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
DUNE_OPTS="--profile=release --display=quiet"
|
||||||
|
exec dune exec $DUNE_OPTS bench/trace1.exe -- $@
|
||||||
Loading…
Add table
Reference in a new issue