mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-07 19:55:39 -05:00
benchs: run with both pool and simple_pool
This commit is contained in:
parent
c03e342178
commit
73c2f9768c
4 changed files with 45 additions and 20 deletions
12
Makefile
12
Makefile
|
|
@ -22,22 +22,24 @@ watch:
|
||||||
DUNE_OPTS_BENCH?=--profile=release
|
DUNE_OPTS_BENCH?=--profile=release
|
||||||
|
|
||||||
N?=40
|
N?=40
|
||||||
NITER?=3
|
NITER?=2
|
||||||
BENCH_PSIZE?=1,4,8,20
|
BENCH_PSIZE?=1,4,8,20
|
||||||
|
BENCH_KIND?=simple,pool
|
||||||
BENCH_CUTOFF?=20
|
BENCH_CUTOFF?=20
|
||||||
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 -L psize $(BENCH_PSIZE) --warmup=1 \
|
hyperfine -L psize $(BENCH_PSIZE) -L kind $(BENCH_KIND) --warmup=1 \
|
||||||
'./_build/default/benchs/fib_rec.exe -cutoff $(BENCH_CUTOFF) -niter $(NITER) -psize={psize} -n $(N)'
|
'./_build/default/benchs/fib_rec.exe -cutoff $(BENCH_CUTOFF) -niter $(NITER) -psize={psize} -kind={kind} -n $(N)'
|
||||||
|
|
||||||
PI_NSTEPS?=100_000_000
|
PI_NSTEPS?=100_000_000
|
||||||
PI_MODES?=seq,par1,forkjoin
|
PI_MODES?=seq,par1,forkjoin
|
||||||
|
PI_KIND?=simple,pool
|
||||||
bench-pi:
|
bench-pi:
|
||||||
@echo running for N=$(PI_NSTEPS)
|
@echo running for N=$(PI_NSTEPS)
|
||||||
dune build $(DUNE_OPTS_BENCH) benchs/pi.exe
|
dune build $(DUNE_OPTS_BENCH) benchs/pi.exe
|
||||||
hyperfine -L mode $(PI_MODES) --warmup=1 \
|
hyperfine -L mode $(PI_MODES) -L kind $(PI_KIND) --warmup=1 \
|
||||||
'./_build/default/benchs/pi.exe -mode={mode} -n $(PI_NSTEPS)'
|
'./_build/default/benchs/pi.exe -mode={mode} -kind={kind} -n $(PI_NSTEPS)'
|
||||||
|
|
||||||
.PHONY: test clean bench-fib bench-pi
|
.PHONY: test clean bench-fib bench-pi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,4 @@
|
||||||
(names fib_rec pi)
|
(names fib_rec pi)
|
||||||
(preprocess (action
|
(preprocess (action
|
||||||
(run %{project_root}/src/cpp/cpp.exe %{input-file})))
|
(run %{project_root}/src/cpp/cpp.exe %{input-file})))
|
||||||
(libraries moonpool unix))
|
(libraries moonpool unix trace trace-tef))
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,14 @@ 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 ~niter () : unit =
|
let create_pool ~psize ~kind () =
|
||||||
let pool = lazy (Pool.create ~min:psize ()) in
|
match kind with
|
||||||
|
| "simple" -> Simple_pool.create ~min:psize ()
|
||||||
|
| "pool" -> Pool.create ~min:psize ()
|
||||||
|
| _ -> assert false
|
||||||
|
|
||||||
|
let run ~psize ~n ~seq ~niter ~kind () : unit =
|
||||||
|
let pool = lazy (create_pool ~kind ~psize ()) in
|
||||||
for _i = 1 to niter do
|
for _i = 1 to niter do
|
||||||
let res =
|
let res =
|
||||||
if seq then (
|
if seq then (
|
||||||
|
|
@ -39,6 +45,7 @@ let () =
|
||||||
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 niter = ref 3 in
|
||||||
|
let kind = ref "pool" in
|
||||||
let opts =
|
let opts =
|
||||||
[
|
[
|
||||||
"-psize", Arg.Set_int psize, " pool size";
|
"-psize", Arg.Set_int psize, " pool size";
|
||||||
|
|
@ -46,9 +53,12 @@ let () =
|
||||||
"-seq", Arg.Set seq, " sequential";
|
"-seq", Arg.Set seq, " sequential";
|
||||||
"-niter", Arg.Set_int niter, " number of iterations";
|
"-niter", Arg.Set_int niter, " number of iterations";
|
||||||
"-cutoff", Arg.Set_int cutoff, " cutoff for sequential computation";
|
"-cutoff", Arg.Set_int cutoff, " cutoff for sequential computation";
|
||||||
|
( "-kind",
|
||||||
|
Arg.Symbol ([ "pool"; "simple" ], ( := ) kind),
|
||||||
|
" pick pool implementation" );
|
||||||
]
|
]
|
||||||
|> Arg.align
|
|> Arg.align
|
||||||
in
|
in
|
||||||
|
|
||||||
Arg.parse opts ignore "";
|
Arg.parse opts ignore "";
|
||||||
run ~psize:!psize ~n:!n ~seq:!seq ~niter:!niter ()
|
run ~psize:!psize ~n:!n ~seq:!seq ~niter:!niter ~kind:!kind ()
|
||||||
|
|
|
||||||
27
benchs/pi.ml
27
benchs/pi.ml
|
|
@ -17,15 +17,23 @@ let run_sequential (num_steps : int) : float =
|
||||||
pi
|
pi
|
||||||
|
|
||||||
(** Create a pool *)
|
(** Create a pool *)
|
||||||
let with_pool f =
|
let with_pool ~kind f =
|
||||||
|
match kind with
|
||||||
|
| "pool" ->
|
||||||
if !j = 0 then
|
if !j = 0 then
|
||||||
Pool.with_ ~per_domain:1 f
|
Pool.with_ ~per_domain:1 f
|
||||||
else
|
else
|
||||||
Pool.with_ ~min:!j f
|
Pool.with_ ~min:!j f
|
||||||
|
| "simple" ->
|
||||||
|
if !j = 0 then
|
||||||
|
Simple_pool.with_ ~per_domain:1 f
|
||||||
|
else
|
||||||
|
Simple_pool.with_ ~min:!j f
|
||||||
|
| _ -> assert false
|
||||||
|
|
||||||
(** Run in parallel using {!Fut.for_} *)
|
(** Run in parallel using {!Fut.for_} *)
|
||||||
let run_par1 (num_steps : int) : float =
|
let run_par1 ~kind (num_steps : int) : float =
|
||||||
let@ pool = with_pool () in
|
let@ pool = with_pool ~kind () in
|
||||||
|
|
||||||
let num_tasks = Pool.size pool in
|
let num_tasks = Pool.size pool in
|
||||||
|
|
||||||
|
|
@ -53,8 +61,8 @@ let run_par1 (num_steps : int) : float =
|
||||||
|
|
||||||
[@@@ifge 5.0]
|
[@@@ifge 5.0]
|
||||||
|
|
||||||
let run_fork_join num_steps : float =
|
let run_fork_join ~kind num_steps : float =
|
||||||
let@ pool = with_pool () in
|
let@ pool = with_pool ~kind () in
|
||||||
|
|
||||||
let num_tasks = Pool.size pool in
|
let num_tasks = Pool.size pool in
|
||||||
|
|
||||||
|
|
@ -90,9 +98,11 @@ type mode =
|
||||||
| Fork_join
|
| Fork_join
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
|
let@ () = Trace_tef.with_setup () in
|
||||||
let mode = ref Sequential in
|
let mode = ref Sequential in
|
||||||
let n = ref 1000 in
|
let n = ref 1000 in
|
||||||
let time = ref false in
|
let time = ref false in
|
||||||
|
let kind = ref "pool" in
|
||||||
|
|
||||||
let set_mode = function
|
let set_mode = function
|
||||||
| "seq" -> mode := Sequential
|
| "seq" -> mode := Sequential
|
||||||
|
|
@ -109,6 +119,9 @@ let () =
|
||||||
" mode of execution" );
|
" mode of execution" );
|
||||||
"-j", Arg.Set_int j, " number of threads";
|
"-j", Arg.Set_int j, " number of threads";
|
||||||
"-t", Arg.Set time, " printing timing";
|
"-t", Arg.Set time, " printing timing";
|
||||||
|
( "-kind",
|
||||||
|
Arg.Symbol ([ "pool"; "simple" ], ( := ) kind),
|
||||||
|
" pick pool implementation" );
|
||||||
]
|
]
|
||||||
|> Arg.align
|
|> Arg.align
|
||||||
in
|
in
|
||||||
|
|
@ -118,8 +131,8 @@ let () =
|
||||||
let res =
|
let res =
|
||||||
match !mode with
|
match !mode with
|
||||||
| Sequential -> run_sequential !n
|
| Sequential -> run_sequential !n
|
||||||
| Par1 -> run_par1 !n
|
| Par1 -> run_par1 ~kind:!kind !n
|
||||||
| Fork_join -> run_fork_join !n
|
| Fork_join -> run_fork_join ~kind:!kind !n
|
||||||
in
|
in
|
||||||
let elapsed : float = Unix.gettimeofday () -. t_start in
|
let elapsed : float = Unix.gettimeofday () -. t_start in
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue