mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
benchs: add pvec
This commit is contained in:
parent
03e253a31c
commit
42967b2127
2 changed files with 46 additions and 13 deletions
|
|
@ -1,6 +1,7 @@
|
|||
(executables
|
||||
(names run_benchs run_bench_hash run_objsize)
|
||||
(libraries containers containers-data containers-thread benchmark gen iter
|
||||
(libraries containers containers_pvec
|
||||
containers-data benchmark gen iter
|
||||
qcheck oseq batteries base sek)
|
||||
(flags :standard -warn-error -3-5 -safe-string -color always)
|
||||
(optional)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ let ( @>> ) = B.Tree.( @>> )
|
|||
let ( @>>> ) = B.Tree.( @>>> )
|
||||
|
||||
module Int_map = Map.Make (CCInt)
|
||||
module Pvec = Containers_pvec
|
||||
|
||||
let app_int f n = string_of_int n @> lazy (f n)
|
||||
let app_ints f l = B.Tree.concat (List.map (app_int f) l)
|
||||
|
|
@ -26,16 +27,19 @@ module L = struct
|
|||
let l = CCList.(1 -- n) in
|
||||
let ral = CCRAL.of_list l in
|
||||
let vec = CCFun_vec.of_list l in
|
||||
let pv = Pvec.of_list l in
|
||||
let sek = Sek.Persistent.of_array 0 (Array.of_list l) in
|
||||
let iter_list () = List.iter f l
|
||||
and raliter () = CCRAL.iter ~f ral
|
||||
and funvec_iter () = CCFun_vec.iter ~f vec
|
||||
and pvec_iter () = Pvec.iter f pv
|
||||
and sek_iter () = Sek.Persistent.iter Sek.forward f sek in
|
||||
B.throughputN time ~repeat
|
||||
[
|
||||
"List.iter", iter_list, ();
|
||||
"CCRAL.iter", raliter, ();
|
||||
"CCFun_vec.iter", funvec_iter, ();
|
||||
"Pvec.iter", pvec_iter, ();
|
||||
"Sek.Persistent.iter", sek_iter, ();
|
||||
]
|
||||
|
||||
|
|
@ -146,6 +150,9 @@ module L = struct
|
|||
let v1 = CCFun_vec.of_list l1 in
|
||||
let v2 = CCFun_vec.of_list l2 in
|
||||
let v3 = CCFun_vec.of_list l3 in
|
||||
let pv1 = Pvec.of_list l1 in
|
||||
let pv2 = Pvec.of_list l2 in
|
||||
let pv3 = Pvec.of_list l3 in
|
||||
let s1 = Sek.Persistent.of_array 0 (Array.of_list l1) in
|
||||
let s2 = Sek.Persistent.of_array 0 (Array.of_list l2) in
|
||||
let s3 = Sek.Persistent.of_array 0 (Array.of_list l3) in
|
||||
|
|
@ -158,6 +165,9 @@ module L = struct
|
|||
let bench_funvec l1 l2 l3 () =
|
||||
opaque_ignore CCFun_vec.(append (append l1 l2) l3)
|
||||
in
|
||||
let bench_pvec l1 l2 l3 () =
|
||||
opaque_ignore Pvec.(append (append l1 l2) l3)
|
||||
in
|
||||
let bench_sek l1 l2 l3 () =
|
||||
opaque_ignore Sek.Persistent.(concat (concat l1 l2) l3)
|
||||
in
|
||||
|
|
@ -166,6 +176,7 @@ module L = struct
|
|||
"CCList.append", bench_list l1 l2 l3, ();
|
||||
"List.append", bench_cclist l1 l2 l3, ();
|
||||
"CCFun_vec.append", bench_funvec v1 v2 v3, ();
|
||||
"Pvec.append", bench_pvec pv1 pv2 pv3, ();
|
||||
"Sek.concat", bench_sek s1 s2 s3, ();
|
||||
]
|
||||
|
||||
|
|
@ -209,6 +220,7 @@ module L = struct
|
|||
let l = CCList.(0 -- (n - 1)) in
|
||||
let ral = CCRAL.of_list l in
|
||||
let v = CCFun_vec.of_list l in
|
||||
let pv = Pvec.of_list l in
|
||||
let bv = BatVect.of_list l in
|
||||
let map =
|
||||
List.fold_left (fun map i -> Int_map.add i i map) Int_map.empty l
|
||||
|
|
@ -230,6 +242,10 @@ module L = struct
|
|||
for i = 0 to n - 1 do
|
||||
opaque_ignore (CCFun_vec.get_exn i l)
|
||||
done
|
||||
and bench_pvec l () =
|
||||
for i = 0 to n - 1 do
|
||||
opaque_ignore (Pvec.get l i)
|
||||
done
|
||||
and bench_batvec l () =
|
||||
for i = 0 to n - 1 do
|
||||
opaque_ignore (BatVect.get l i)
|
||||
|
|
@ -245,6 +261,7 @@ module L = struct
|
|||
"Map.find", bench_map map, ();
|
||||
"RAL.get", bench_ral ral, ();
|
||||
"funvec.get", bench_funvec v, ();
|
||||
"pvec.get", bench_pvec pv, ();
|
||||
"batvec.get", bench_batvec bv, ();
|
||||
"Sek.Persistent.get", bench_sek sek, ();
|
||||
]
|
||||
|
|
@ -290,11 +307,8 @@ module L = struct
|
|||
|
||||
let bench_push ?(time = 2) n =
|
||||
(*let ral = ref CCRAL.empty in *)
|
||||
let v = ref CCFun_vec.empty in
|
||||
let bv = ref BatVect.empty in
|
||||
let map = ref Int_map.empty in
|
||||
let sek = ref (Sek.Persistent.create 0) in
|
||||
let bench_map l () =
|
||||
let bench_map () =
|
||||
let l = ref Int_map.empty in
|
||||
for i = 0 to n - 1 do
|
||||
l := Int_map.add i i !l
|
||||
done;
|
||||
|
|
@ -304,17 +318,26 @@ module L = struct
|
|||
(* Note: Better implementation probably possible *)
|
||||
for i = 0 to n-1 do l := CCRAL.append !l (CCRAL.return i) done; opaque_ignore l
|
||||
*)
|
||||
and bench_funvec l () =
|
||||
and bench_funvec () =
|
||||
let l = ref CCFun_vec.empty in
|
||||
for i = 0 to n - 1 do
|
||||
l := CCFun_vec.push i !l
|
||||
done;
|
||||
opaque_ignore l
|
||||
and bench_batvec l () =
|
||||
and bench_pvec () =
|
||||
let l = ref Pvec.empty in
|
||||
for i = 0 to n - 1 do
|
||||
l := Pvec.push !l i
|
||||
done;
|
||||
opaque_ignore l
|
||||
and bench_batvec () =
|
||||
let l = ref BatVect.empty in
|
||||
for i = 0 to n - 1 do
|
||||
l := BatVect.append i !l
|
||||
done;
|
||||
opaque_ignore l
|
||||
and bench_sek l () =
|
||||
and bench_sek () =
|
||||
let l = ref (Sek.Persistent.create 0) in
|
||||
for i = 0 to n - 1 do
|
||||
l := Sek.Persistent.push Sek.front !l i
|
||||
done;
|
||||
|
|
@ -322,18 +345,20 @@ module L = struct
|
|||
in
|
||||
B.throughputN time ~repeat
|
||||
[
|
||||
"Map.add", bench_map map, ()
|
||||
"Map.add", bench_map, ()
|
||||
(* ; "RAL.append", bench_ral ral, () *)
|
||||
(* too slow *);
|
||||
"Sek.Persistent.push", bench_sek sek, ();
|
||||
"funvec.push", bench_funvec v, ();
|
||||
"batvec.append", bench_batvec bv, ();
|
||||
"Sek.Persistent.push", bench_sek, ();
|
||||
"funvec.push", bench_funvec, ();
|
||||
"pvec.push", bench_pvec, ();
|
||||
"batvec.append", bench_batvec, ();
|
||||
]
|
||||
|
||||
let bench_pop ?(time = 2) n =
|
||||
let l = CCList.(0 -- (n - 1)) in
|
||||
let ral = CCRAL.of_list l in
|
||||
let v = CCFun_vec.of_list l in
|
||||
let pv = Pvec.of_list l in
|
||||
let bv = BatVect.of_list l in
|
||||
let map =
|
||||
List.fold_left (fun map i -> Int_map.add i i map) Int_map.empty l
|
||||
|
|
@ -357,6 +382,12 @@ module L = struct
|
|||
l := snd (CCFun_vec.pop_exn !l)
|
||||
done;
|
||||
opaque_ignore l
|
||||
and bench_pvec l () =
|
||||
let l = ref l in
|
||||
for _ = 0 to n - 1 do
|
||||
l := snd (Pvec.pop !l)
|
||||
done;
|
||||
opaque_ignore l
|
||||
and bench_batvec l () =
|
||||
let l = ref l in
|
||||
for _ = 0 to n - 1 do
|
||||
|
|
@ -375,6 +406,7 @@ module L = struct
|
|||
"Map.remove", bench_map map, ();
|
||||
"RAL.tl", bench_ral ral, ();
|
||||
"funvec.pop", bench_funvec v, ();
|
||||
"pvec.pop", bench_pvec pv, ();
|
||||
"batvec.pop", bench_batvec bv, ();
|
||||
"Sek.Persistent.pop", bench_sek sek, ();
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue