bench: add -niter param

This commit is contained in:
Simon Cruanes 2023-06-07 21:23:15 -04:00
parent 65b3d8de06
commit c77b579caa
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 22 additions and 17 deletions

View file

@ -19,13 +19,14 @@ watch:
DUNE_OPTS_BENCH?=--profile=release DUNE_OPTS_BENCH?=--profile=release
N?=40 N?=40
NITER?=3
bench-fib: bench-fib:
@echo running for N=$(N) @echo running for N=$(N)
dune build $(DUNE_OPTS_BENCH) benchs/fib_rec.exe dune build $(DUNE_OPTS_BENCH) benchs/fib_rec.exe
hyperfine \ hyperfine \
'./_build/default/benchs/fib_rec.exe -psize=1 -n $(N)' \ './_build/default/benchs/fib_rec.exe -niter $(NITER) -psize=1 -n $(N)' \
'./_build/default/benchs/fib_rec.exe -psize=8 -n $(N)' \ './_build/default/benchs/fib_rec.exe -niter $(NITER) -psize=8 -n $(N)' \
'./_build/default/benchs/fib_rec.exe -psize=20 -n $(N)' \ './_build/default/benchs/fib_rec.exe -niter $(NITER) -psize=20 -n $(N)' \
'./_build/default/benchs/fib_rec.exe -n $(N) -seq' './_build/default/benchs/fib_rec.exe -niter $(NITER) -n $(N) -seq'
.PHONY: test clean .PHONY: test clean

View file

@ -16,31 +16,35 @@ let rec fib ~on x : int Fut.t =
let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ]) let () = assert (List.init 10 fib_direct = [ 1; 1; 2; 3; 5; 8; 13; 21; 34; 55 ])
let run ~psize ~n ~seq () : unit = let run ~psize ~n ~seq ~niter () : unit =
let pool = lazy (Pool.create ~min:psize ()) in
for _i = 1 to niter do
let res = let res =
if seq then ( if seq then (
Printf.printf "compute fib %d sequentially\n%!" n; Printf.printf "compute fib %d sequentially\n%!" n;
fib_direct n fib_direct n
) else ( ) else (
Printf.printf "compute fib %d with pool size=%d\n%!" n psize; Printf.printf "compute fib %d with pool size=%d\n%!" n psize;
let pool = Pool.create ~min:psize () in fib ~on:(Lazy.force pool) n |> Fut.wait_block_exn
fib ~on:pool n |> Fut.wait_block_exn
) )
in in
Printf.printf "fib %d = %d\n%!" n res Printf.printf "fib %d = %d\n%!" n res
done
let () = let () =
let n = ref 40 in let n = ref 40 in
let psize = ref 16 in let psize = ref 16 in
let seq = ref false in let seq = ref false in
let niter = ref 3 in
let opts = let opts =
[ [
"-psize", Arg.Set_int psize, " pool size"; "-psize", Arg.Set_int psize, " pool size";
"-n", Arg.Set_int n, " fib <n>"; "-n", Arg.Set_int n, " fib <n>";
"-seq", Arg.Set seq, " sequential"; "-seq", Arg.Set seq, " sequential";
"-niter", Arg.Set_int niter, " number of iterations";
] ]
|> Arg.align |> Arg.align
in in
Arg.parse opts ignore ""; Arg.parse opts ignore "";
run ~psize:!psize ~n:!n ~seq:!seq () run ~psize:!psize ~n:!n ~seq:!seq ~niter:!niter ()