mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
update tests and benchs for new Fut API
This commit is contained in:
parent
59ae1068fd
commit
62e8336d84
4 changed files with 10 additions and 15 deletions
|
|
@ -12,7 +12,7 @@ let rec fib ~on x : int Fut.t =
|
|||
if x <= !cutoff then
|
||||
Fut.spawn ~on (fun () -> fib_direct x)
|
||||
else
|
||||
let open Fut.Infix_local in
|
||||
let open Fut.Infix in
|
||||
let+ t1 = fib ~on (x - 1) and+ t2 = fib ~on (x - 2) in
|
||||
t1 + t2
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ let run ~pool () =
|
|||
0 l)
|
||||
in
|
||||
|
||||
let futs =
|
||||
List.init n_tasks (fun _ -> Fut.spawn ~on:pool task |> Fut.join ~on:pool)
|
||||
in
|
||||
let futs = List.init n_tasks (fun _ -> Fut.spawn ~on:pool task |> Fut.join) in
|
||||
|
||||
let lens = List.map Fut.wait_block_exn futs in
|
||||
Printf.printf "awaited %d items (%d times)\n%!" (List.hd lens) n_tasks;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ open Moonpool
|
|||
(* large pool, some of our tasks below are long lived *)
|
||||
let pool = Ws_pool.create ~num_threads:30 ()
|
||||
|
||||
open (val Fut.infix pool)
|
||||
open Fut.Infix
|
||||
|
||||
type event =
|
||||
| E_int of int
|
||||
|
|
|
|||
|
|
@ -15,19 +15,16 @@ let rec mk_tree ~pool n : _ tree Fut.t =
|
|||
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "mk-tree" in
|
||||
if n <= 1 then
|
||||
Fut.return (Leaf 1)
|
||||
else
|
||||
let open (val Fut.infix pool) in
|
||||
let l =
|
||||
Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join ~on:pool
|
||||
and r =
|
||||
Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join ~on:pool
|
||||
in
|
||||
else (
|
||||
let l = Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join
|
||||
and r = Fut.spawn ~on:pool (fun () -> mk_tree ~pool (n - 1)) |> Fut.join in
|
||||
|
||||
Fut.return @@ Node (l, r)
|
||||
)
|
||||
|
||||
let rec rev ~pool (t : 'a tree Fut.t) : 'a tree Fut.t =
|
||||
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "rev" in
|
||||
let open (val Fut.infix pool) in
|
||||
let open Fut.Infix in
|
||||
t >>= function
|
||||
| Leaf n -> Fut.return (Leaf n)
|
||||
| Node (l, r) ->
|
||||
|
|
@ -36,7 +33,7 @@ let rec rev ~pool (t : 'a tree Fut.t) : 'a tree Fut.t =
|
|||
|
||||
let rec sum ~pool (t : int tree Fut.t) : int Fut.t =
|
||||
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "sum" in
|
||||
let open (val Fut.infix pool) in
|
||||
let open Fut.Infix in
|
||||
t >>= function
|
||||
| Leaf n -> Fut.return n
|
||||
| Node (l, r) ->
|
||||
|
|
@ -45,7 +42,7 @@ let rec sum ~pool (t : int tree Fut.t) : int Fut.t =
|
|||
|
||||
let run ~pool n : (int * int) Fut.t =
|
||||
let@ _sp = Trace.with_span ~__FILE__ ~__LINE__ "run" in
|
||||
let open (val Fut.infix pool) in
|
||||
let open Fut.Infix in
|
||||
let t = Fut.return n >>= mk_tree ~pool in
|
||||
let t' = rev ~pool t in
|
||||
let sum_t = sum ~pool t in
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue