mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
chore: fix benchs so they don't depend on clarity and they compile again
This commit is contained in:
parent
7d1862a501
commit
936d5912e6
2 changed files with 38 additions and 48 deletions
|
|
@ -2,9 +2,9 @@
|
||||||
(executables
|
(executables
|
||||||
(names run_benchs run_bench_hash)
|
(names run_benchs run_bench_hash)
|
||||||
(libraries containers containers.data containers.iter
|
(libraries containers containers.data containers.iter
|
||||||
containers.thread benchmark gen iter qcheck
|
containers.thread benchmark gen iter qcheck oseq
|
||||||
batteries clarity)
|
batteries)
|
||||||
(flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -color always -open CCShims_)
|
(flags :standard -warn-error -3 -safe-string -color always -open CCShims_)
|
||||||
(ocamlopt_flags :standard -O3 -color always
|
(ocamlopt_flags :standard -O3 -color always
|
||||||
-unbox-closures -unbox-closures-factor 20)
|
-unbox-closures -unbox-closures-factor 20)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,6 @@ module L = struct
|
||||||
let ral = CCRAL.of_list l in
|
let ral = CCRAL.of_list l in
|
||||||
let v = CCFun_vec.of_list l in
|
let v = CCFun_vec.of_list l in
|
||||||
let bv = BatVect.of_list l in
|
let bv = BatVect.of_list l in
|
||||||
let cv = Clarity.Vector.of_list l in
|
|
||||||
let map = List.fold_left (fun map i -> Int_map.add i i map) Int_map.empty l in
|
let map = List.fold_left (fun map i -> Int_map.add i i map) Int_map.empty l in
|
||||||
let bench_list l () =
|
let bench_list l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (List.nth l i)) done
|
for i = 0 to n-1 do Sys.opaque_identity (ignore (List.nth l i)) done
|
||||||
|
|
@ -126,8 +125,6 @@ module L = struct
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (CCFun_vec.get_exn i l)) done
|
for i = 0 to n-1 do Sys.opaque_identity (ignore (CCFun_vec.get_exn i l)) done
|
||||||
and bench_batvec l () =
|
and bench_batvec l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (BatVect.get l i)) done
|
for i = 0 to n-1 do Sys.opaque_identity (ignore (BatVect.get l i)) done
|
||||||
and bench_clarity_vec l () =
|
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (Clarity.Vector.get l i)) done
|
|
||||||
in
|
in
|
||||||
B.throughputN time ~repeat
|
B.throughputN time ~repeat
|
||||||
[ "List.nth", bench_list l, ()
|
[ "List.nth", bench_list l, ()
|
||||||
|
|
@ -135,61 +132,54 @@ module L = struct
|
||||||
; "RAL.get", bench_ral ral, ()
|
; "RAL.get", bench_ral ral, ()
|
||||||
; "funvec.get", bench_funvec v, ()
|
; "funvec.get", bench_funvec v, ()
|
||||||
; "batvec.get", bench_batvec bv, ()
|
; "batvec.get", bench_batvec bv, ()
|
||||||
; "clarity_vec.get", bench_clarity_vec cv, ()
|
|
||||||
]
|
]
|
||||||
|
|
||||||
let bench_set ?(time=2) n =
|
let bench_set ?(time=2) n =
|
||||||
let l = CCList.(0 -- (n - 1)) in
|
let l = CCList.(0 -- (n - 1)) in
|
||||||
let ral = CCRAL.of_list l in
|
let ral = CCRAL.of_list l in
|
||||||
let v = CCFun_vec.of_list l in
|
(* let v = CCFun_vec.of_list l in *)
|
||||||
let bv = BatVect.of_list l in
|
let bv = BatVect.of_list l in
|
||||||
let cv = Clarity.Vector.of_list l in
|
|
||||||
let map = List.fold_left (fun map i -> Int_map.add i i map) Int_map.empty l in
|
let map = List.fold_left (fun map i -> Int_map.add i i map) Int_map.empty l in
|
||||||
let bench_map l () =
|
let bench_map l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (Int_map.add i (-i) l)) done
|
for i = 0 to n-1 do Sys.opaque_identity (ignore (Int_map.add i (-i) l)) done
|
||||||
and bench_ral l () =
|
and bench_ral l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (CCRAL.set l i (-i))) done
|
for i = 0 to n-1 do Sys.opaque_identity (ignore (CCRAL.set l i (-i))) done
|
||||||
|
(*
|
||||||
and bench_funvec l () =
|
and bench_funvec l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore ((* TODO *))) done
|
for _i = 0 to n-1 do Sys.opaque_identity (ignore ((* TODO *))) done
|
||||||
|
*)
|
||||||
and bench_batvec l () =
|
and bench_batvec l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (BatVect.set l i (-i))) done
|
for i = 0 to n-1 do Sys.opaque_identity (ignore (BatVect.set l i (-i))) done
|
||||||
and bench_clarity_vec l () =
|
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (ignore (Clarity.Vector.update l i (-1))) done
|
|
||||||
in
|
in
|
||||||
B.throughputN time ~repeat
|
B.throughputN time ~repeat
|
||||||
[ "Map.add", bench_map map, ()
|
[ "Map.add", bench_map map, ()
|
||||||
; "RAL.set", bench_ral ral, ()
|
; "RAL.set", bench_ral ral, ()
|
||||||
(* ; "funvec.set", bench_funvec v, () *)
|
(* ; "funvec.set", bench_funvec v, () *)
|
||||||
; "batvec.set", bench_batvec bv, ()
|
; "batvec.set", bench_batvec bv, ()
|
||||||
; "clarity_vec.update", bench_clarity_vec cv, ()
|
|
||||||
]
|
]
|
||||||
|
|
||||||
let bench_push ?(time=2) n =
|
let bench_push ?(time=2) n =
|
||||||
let l = ref CCList.empty in
|
(*let ral = ref CCRAL.empty in *)
|
||||||
let ral = ref CCRAL.empty in
|
|
||||||
let v = ref CCFun_vec.empty in
|
let v = ref CCFun_vec.empty in
|
||||||
let bv = ref BatVect.empty in
|
let bv = ref BatVect.empty in
|
||||||
let cv = ref Clarity.Vector.empty in
|
|
||||||
let map = ref Int_map.empty in
|
let map = ref Int_map.empty in
|
||||||
let bench_map l () =
|
let bench_map l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (l := Int_map.add i i !l) done
|
for i = 0 to n-1 do Sys.opaque_identity (l := Int_map.add i i !l) done
|
||||||
and bench_ral l () =
|
(*
|
||||||
(* Note: Better implementation probably possible *)
|
and bench_ral l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (l := CCRAL.append !l (CCRAL.return i)) done
|
(* Note: Better implementation probably possible *)
|
||||||
|
for i = 0 to n-1 do Sys.opaque_identity (l := CCRAL.append !l (CCRAL.return i)) done
|
||||||
|
*)
|
||||||
and bench_funvec l () =
|
and bench_funvec l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (l := CCFun_vec.push i !l) done
|
for i = 0 to n-1 do Sys.opaque_identity (l := CCFun_vec.push i !l) done
|
||||||
and bench_batvec l () =
|
and bench_batvec l () =
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (l := BatVect.append i !l) done
|
for i = 0 to n-1 do Sys.opaque_identity (l := BatVect.append i !l) done
|
||||||
and bench_clarity_vec l () =
|
|
||||||
(* Note: Better implementation probably possible *)
|
|
||||||
for i = 0 to n-1 do Sys.opaque_identity (l := Clarity.Vector.append !l (Clarity.Vector.pure i)) done
|
|
||||||
in
|
in
|
||||||
B.throughputN time ~repeat
|
B.throughputN time ~repeat
|
||||||
[ "Map.add", bench_map map, ()
|
[ "Map.add", bench_map map, ()
|
||||||
(* ; "RAL.append", bench_ral ral, () *) (* too slow *)
|
(* ; "RAL.append", bench_ral ral, () *) (* too slow *)
|
||||||
; "funvec.push", bench_funvec v, ()
|
; "funvec.push", bench_funvec v, ()
|
||||||
; "batvec.append", bench_batvec bv, ()
|
; "batvec.append", bench_batvec bv, ()
|
||||||
; "clarity_vec.append", bench_clarity_vec cv, ()
|
|
||||||
]
|
]
|
||||||
|
|
||||||
(* MAIN *)
|
(* MAIN *)
|
||||||
|
|
@ -808,40 +798,40 @@ module Tbl = struct
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
module Iter = struct
|
module Iter_ = struct
|
||||||
(** {2 Sequence/Gen} *)
|
(** {2 Iter/Gen} *)
|
||||||
|
|
||||||
let bench_fold n =
|
let bench_fold n =
|
||||||
let seq () = Sequence.fold (+) 0 Sequence.(0 --n) in
|
let iter () = Iter.fold (+) 0 Iter.(0 --n) in
|
||||||
let gen () = Gen.fold (+) 0 Gen.(0 -- n) in
|
let gen () = Gen.fold (+) 0 Gen.(0 -- n) in
|
||||||
let klist () = CCKList.fold (+) 0 CCKList.(0 -- n) in
|
let klist () = OSeq.fold (+) 0 OSeq.(0 -- n) in
|
||||||
B.throughputN 3 ~repeat
|
B.throughputN 3 ~repeat
|
||||||
[ "sequence.fold", seq, ();
|
[ "iter.fold", iter, ();
|
||||||
"gen.fold", gen, ();
|
"gen.fold", gen, ();
|
||||||
"klist.fold", klist, ();
|
"klist.fold", klist, ();
|
||||||
]
|
]
|
||||||
|
|
||||||
let bench_flat_map n =
|
let bench_flat_map n =
|
||||||
let seq () = Sequence.(
|
let iter () = Iter.(
|
||||||
0 -- n |> flat_map (fun x -> x-- (x+10)) |> fold (+) 0
|
0 -- n |> flat_map (fun x -> x-- (x+10)) |> fold (+) 0
|
||||||
)
|
)
|
||||||
and gen () = Gen.(
|
and gen () = Gen.(
|
||||||
0 -- n |> flat_map (fun x -> x-- (x+10)) |> fold (+) 0
|
0 -- n |> flat_map (fun x -> x-- (x+10)) |> fold (+) 0
|
||||||
)
|
)
|
||||||
and klist () = CCKList.(
|
and oseq () = OSeq.(
|
||||||
0 -- n |> flat_map (fun x -> x-- (x+10)) |> fold (+) 0
|
0 -- n |> flat_map (fun x -> x-- (x+10)) |> fold (+) 0
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
B.throughputN 3 ~repeat
|
B.throughputN 3 ~repeat
|
||||||
[ "sequence.flat_map", seq, ();
|
[ "sequence.flat_map", iter, ();
|
||||||
"gen.flat_map", gen, ();
|
"gen.flat_map", gen, ();
|
||||||
"klist.flat_map", klist, ();
|
"oseq.flat_map", oseq, ();
|
||||||
]
|
]
|
||||||
|
|
||||||
let bench_iter n =
|
let bench_iter n =
|
||||||
let seq () =
|
let iter () =
|
||||||
let i = ref 2 in
|
let i = ref 2 in
|
||||||
Sequence.(
|
Iter.(
|
||||||
1 -- n |> iter (fun x -> i := !i * x)
|
1 -- n |> iter (fun x -> i := !i * x)
|
||||||
)
|
)
|
||||||
and gen () =
|
and gen () =
|
||||||
|
|
@ -849,16 +839,16 @@ module Iter = struct
|
||||||
Gen.(
|
Gen.(
|
||||||
1 -- n |> iter (fun x -> i := !i * x)
|
1 -- n |> iter (fun x -> i := !i * x)
|
||||||
)
|
)
|
||||||
and klist () =
|
and oseq () =
|
||||||
let i = ref 2 in
|
let i = ref 2 in
|
||||||
CCKList.(
|
OSeq.(
|
||||||
1 -- n |> iter (fun x -> i := !i * x)
|
1 -- n |> iter (fun x -> i := !i * x)
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
B.throughputN 3 ~repeat
|
B.throughputN 3 ~repeat
|
||||||
[ "sequence.iter", seq, ();
|
[ "iter.iter", iter, ();
|
||||||
"gen.iter", gen, ();
|
"gen.iter", gen, ();
|
||||||
"klist.iter", klist, ();
|
"oseq.iter", oseq, ();
|
||||||
]
|
]
|
||||||
|
|
||||||
let () = B.Tree.register (
|
let () = B.Tree.register (
|
||||||
|
|
@ -873,7 +863,7 @@ module Deque = struct
|
||||||
module type DEQUE = sig
|
module type DEQUE = sig
|
||||||
type 'a t
|
type 'a t
|
||||||
val create : unit -> 'a t
|
val create : unit -> 'a t
|
||||||
val of_seq : 'a Sequence.t -> 'a t
|
val of_seq : 'a Iter.t -> 'a t
|
||||||
val iter : ('a -> unit) -> 'a t -> unit
|
val iter : ('a -> unit) -> 'a t -> unit
|
||||||
val push_front : 'a t -> 'a -> unit
|
val push_front : 'a t -> 'a -> unit
|
||||||
val push_back : 'a t -> 'a -> unit
|
val push_back : 'a t -> 'a -> unit
|
||||||
|
|
@ -1000,7 +990,7 @@ module Deque = struct
|
||||||
let fqueue = (module FQueue : DEQUE)
|
let fqueue = (module FQueue : DEQUE)
|
||||||
|
|
||||||
let bench_iter n =
|
let bench_iter n =
|
||||||
let seq = Sequence.(1 -- n) in
|
let seq = Iter.(1 -- n) in
|
||||||
let make (module D : DEQUE) =
|
let make (module D : DEQUE) =
|
||||||
let q = D.of_seq seq in
|
let q = D.of_seq seq in
|
||||||
fun () ->
|
fun () ->
|
||||||
|
|
@ -1038,7 +1028,7 @@ module Deque = struct
|
||||||
]
|
]
|
||||||
|
|
||||||
let bench_append n =
|
let bench_append n =
|
||||||
let seq = Sequence.(1 -- n) in
|
let seq = Iter.(1 -- n) in
|
||||||
let make (module D :DEQUE) =
|
let make (module D :DEQUE) =
|
||||||
let q1 = D.of_seq seq in
|
let q1 = D.of_seq seq in
|
||||||
let q2 = D.of_seq seq in
|
let q2 = D.of_seq seq in
|
||||||
|
|
@ -1051,7 +1041,7 @@ module Deque = struct
|
||||||
]
|
]
|
||||||
|
|
||||||
let bench_length n =
|
let bench_length n =
|
||||||
let seq = Sequence.(1--n) in
|
let seq = Iter.(1--n) in
|
||||||
let make (module D:DEQUE) =
|
let make (module D:DEQUE) =
|
||||||
let q = D.of_seq seq in
|
let q = D.of_seq seq in
|
||||||
fun () -> ignore (D.length q)
|
fun () -> ignore (D.length q)
|
||||||
|
|
@ -1108,14 +1098,14 @@ module Graph = struct
|
||||||
let dfs_ n () =
|
let dfs_ n () =
|
||||||
let tbl = CCGraph.mk_table ~eq:CCInt.equal ~hash:CCInt.hash (n+10) in
|
let tbl = CCGraph.mk_table ~eq:CCInt.equal ~hash:CCInt.hash (n+10) in
|
||||||
CCGraph.Traverse.dfs ~tbl ~graph:div_graph_
|
CCGraph.Traverse.dfs ~tbl ~graph:div_graph_
|
||||||
(Sequence.return n)
|
(Iter.return n)
|
||||||
|> Sequence.fold (fun acc _ -> acc+1) 0
|
|> Iter.fold (fun acc _ -> acc+1) 0
|
||||||
|
|
||||||
let dfs_event n () =
|
let dfs_event n () =
|
||||||
let tbl = CCGraph.mk_table ~eq:CCInt.equal ~hash:CCInt.hash (n+10) in
|
let tbl = CCGraph.mk_table ~eq:CCInt.equal ~hash:CCInt.hash (n+10) in
|
||||||
CCGraph.Traverse.Event.dfs ~tbl ~eq:CCInt.equal ~graph:div_graph_
|
CCGraph.Traverse.Event.dfs ~tbl ~eq:CCInt.equal ~graph:div_graph_
|
||||||
(Sequence.return n)
|
(Iter.return n)
|
||||||
|> Sequence.fold
|
|> Iter.fold
|
||||||
(fun acc -> function
|
(fun acc -> function
|
||||||
| `Enter _ -> acc+1
|
| `Enter _ -> acc+1
|
||||||
| `Exit _
|
| `Exit _
|
||||||
|
|
@ -1156,7 +1146,7 @@ module Str = struct
|
||||||
let i = ref start in
|
let i = ref start in
|
||||||
try
|
try
|
||||||
while !i + n <= String.length s do
|
while !i + n <= String.length s do
|
||||||
if CCString.is_sub ~sub 0 s !i ~len:n then raise Exit;
|
if CCString.is_sub ~sub 0 s !i ~sub_len:n then raise Exit;
|
||||||
incr i
|
incr i
|
||||||
done;
|
done;
|
||||||
-1
|
-1
|
||||||
|
|
@ -1168,7 +1158,7 @@ module Str = struct
|
||||||
let i = ref (String.length s - n) in
|
let i = ref (String.length s - n) in
|
||||||
try
|
try
|
||||||
while !i >= 0 do
|
while !i >= 0 do
|
||||||
if CCString.is_sub ~sub 0 s !i ~len:n then raise Exit;
|
if CCString.is_sub ~sub 0 s !i ~sub_len:n then raise Exit;
|
||||||
decr i
|
decr i
|
||||||
done;
|
done;
|
||||||
~-1
|
~-1
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue