mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 03:05:30 -05:00
57 lines
1.3 KiB
OCaml
57 lines
1.3 KiB
OCaml
[@@@ifge 5.0]
|
|
|
|
module Q = QCheck
|
|
|
|
let spf = Printf.sprintf
|
|
let ( let@ ) = ( @@ )
|
|
let ppl = Q.Print.(list @@ list int)
|
|
|
|
open! Moonpool
|
|
|
|
let run ~min () =
|
|
let@ _sp =
|
|
Trace.with_span ~__FILE__ ~__LINE__ "run" ~data:(fun () ->
|
|
[ "min", `Int min ])
|
|
in
|
|
|
|
Printf.printf "run with min=%d\n%!" min;
|
|
let neg x = -x in
|
|
|
|
let chunk_size = 100 in
|
|
let l = List.init 300 (fun _ -> List.init 15 (fun i -> i)) in
|
|
|
|
let ref_l1 = List.map (List.map neg) l in
|
|
let ref_l2 = List.map (List.map neg) ref_l1 in
|
|
|
|
for _i = 1 to 800 do
|
|
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "step" in
|
|
|
|
let l1, l2 =
|
|
let@ pool = Pool.with_ ~min () in
|
|
let@ () = Pool.run_wait_block pool in
|
|
|
|
let l1, l2 =
|
|
Fork_join.both
|
|
(fun () ->
|
|
Fork_join.map_list ~chunk_size
|
|
(Fork_join.map_list ~chunk_size neg)
|
|
l)
|
|
(fun () ->
|
|
Fork_join.map_list ~chunk_size
|
|
(Fork_join.map_list ~chunk_size neg)
|
|
ref_l1)
|
|
in
|
|
l1, l2
|
|
in
|
|
|
|
if l1 <> ref_l1 then failwith (spf "l1=%s, ref_l1=%s" (ppl l1) (ppl ref_l1));
|
|
if l2 <> ref_l2 then failwith (spf "l1=%s, ref_l1=%s" (ppl l2) (ppl ref_l2))
|
|
done
|
|
|
|
let () =
|
|
let@ () = Trace_tef.with_setup () in
|
|
run ~min:4 ();
|
|
run ~min:1 ();
|
|
Printf.printf "done\n%!"
|
|
|
|
[@@@endif]
|