mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
add little benchmark tool in test + start script
This commit is contained in:
parent
f9ba356657
commit
4e321b9c46
4 changed files with 67 additions and 3 deletions
5
Makefile
5
Makefile
|
|
@ -6,6 +6,11 @@ all:
|
||||||
clean:
|
clean:
|
||||||
@dune clean
|
@dune clean
|
||||||
|
|
||||||
|
test:
|
||||||
|
@dune runtest $(DUNE_OPTS)
|
||||||
|
|
||||||
WATCH?=@all
|
WATCH?=@all
|
||||||
watch:
|
watch:
|
||||||
dune build $(DUNE_OPTS) -w $(WATCH)
|
dune build $(DUNE_OPTS) -w $(WATCH)
|
||||||
|
|
||||||
|
.PHONY: test clean
|
||||||
|
|
|
||||||
2
bench1.sh
Executable file
2
bench1.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
exec dune exec --release --display=quiet -- test/t_bench1.exe $@
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
(test
|
(tests
|
||||||
(name t_fib)
|
(names t_fib t_bench1)
|
||||||
(libraries moonpool))
|
(libraries moonpool tracy tracy-client))
|
||||||
|
|
|
||||||
57
test/t_bench1.ml
Normal file
57
test/t_bench1.ml
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
open Moonpool
|
||||||
|
|
||||||
|
let ( let@ ) = ( @@ )
|
||||||
|
|
||||||
|
let rec fib x =
|
||||||
|
if x <= 1 then
|
||||||
|
1
|
||||||
|
else
|
||||||
|
fib (x - 1) + fib (x - 2)
|
||||||
|
|
||||||
|
let run ~psize ~n ~j () : _ Fut.t =
|
||||||
|
Printf.printf "pool size=%d, n=%d, j=%d\n%!" psize n j;
|
||||||
|
let pool =
|
||||||
|
Pool.create
|
||||||
|
~on_init_thread:(fun ~dom_id:_ ~t_id () ->
|
||||||
|
Tracy.name_thread (Printf.sprintf "t_%d" t_id))
|
||||||
|
~min:psize ~per_domain:0 ()
|
||||||
|
in
|
||||||
|
|
||||||
|
let loop () =
|
||||||
|
let@ _sp = Tracy.with_ ~file:__FILE__ ~line:__LINE__ ~name:"loop" () in
|
||||||
|
for _i = 1 to n do
|
||||||
|
let () =
|
||||||
|
let@ _sp = Tracy.with_ ~file:__FILE__ ~line:__LINE__ ~name:"iter" () in
|
||||||
|
Tracy.add_text _sp (string_of_int _i);
|
||||||
|
ignore (Sys.opaque_identity (fib 30) : int)
|
||||||
|
in
|
||||||
|
|
||||||
|
Thread.yield ()
|
||||||
|
done
|
||||||
|
in
|
||||||
|
|
||||||
|
let fut = Fut.for_ ~on:pool j (fun _ -> loop ()) in
|
||||||
|
fut
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Tracy.enable ();
|
||||||
|
let j = ref 10 in
|
||||||
|
let n = ref 10 in
|
||||||
|
let psize = ref 4 in
|
||||||
|
let opts =
|
||||||
|
[
|
||||||
|
"-psize", Arg.Set_int psize, " pool size";
|
||||||
|
"-j", Arg.Set_int j, " number of tasks";
|
||||||
|
"-n", Arg.Set_int n, " number of iterations per task";
|
||||||
|
]
|
||||||
|
|> Arg.align
|
||||||
|
in
|
||||||
|
Arg.parse opts ignore "";
|
||||||
|
|
||||||
|
(* start two distinct pools *)
|
||||||
|
let fut1 = run ~psize:!psize ~n:!n ~j:!j () in
|
||||||
|
let fut2 = run ~psize:!psize ~n:!n ~j:!j () in
|
||||||
|
|
||||||
|
Fut.wait_block_exn fut1;
|
||||||
|
Fut.wait_block_exn fut2;
|
||||||
|
Printf.printf "done\n%!"
|
||||||
Loading…
Add table
Reference in a new issue