mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
update benchmarks to use ~repeat arguments
This commit is contained in:
parent
895c8a73d9
commit
c9a4bbd75a
2 changed files with 23 additions and 19 deletions
1
.merlin
1
.merlin
|
|
@ -34,4 +34,5 @@ PKG lwt
|
||||||
PKG bigarray
|
PKG bigarray
|
||||||
PKG sequence
|
PKG sequence
|
||||||
PKG hamt
|
PKG hamt
|
||||||
|
PKG gen
|
||||||
FLG -w +a -w -4 -w -44 -w -32 -w -34
|
FLG -w +a -w -4 -w -44 -w -32 -w -34
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ let (|>) = CCFun.(|>)
|
||||||
let app_int f n = string_of_int n @> lazy (f n)
|
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)
|
let app_ints f l = B.Tree.concat (List.map (app_int f) l)
|
||||||
|
|
||||||
|
(* for benchmark *)
|
||||||
|
let repeat = 3
|
||||||
|
|
||||||
(* composition *)
|
(* composition *)
|
||||||
let (%%) f g x = f (g x)
|
let (%%) f g x = f (g x)
|
||||||
|
|
||||||
|
|
@ -24,7 +27,7 @@ module L = struct
|
||||||
let l = CCList.(1 -- n) in
|
let l = CCList.(1 -- n) in
|
||||||
let flatten_map_ l = List.flatten (CCList.map f_ l)
|
let flatten_map_ l = List.flatten (CCList.map f_ l)
|
||||||
and flatten_ccmap_ l = List.flatten (List.map f_ l) in
|
and flatten_ccmap_ l = List.flatten (List.map f_ l) in
|
||||||
B.throughputN time
|
B.throughputN time ~repeat
|
||||||
[ "flat_map", CCList.flat_map f_, l
|
[ "flat_map", CCList.flat_map f_, l
|
||||||
; "flatten o CCList.map", flatten_ccmap_, l
|
; "flatten o CCList.map", flatten_ccmap_, l
|
||||||
; "flatten o map", flatten_map_, l
|
; "flatten o map", flatten_map_, l
|
||||||
|
|
@ -40,7 +43,7 @@ module L = struct
|
||||||
let l2 = CCList.(n+1 -- 2*n) in
|
let l2 = CCList.(n+1 -- 2*n) in
|
||||||
let l3 = CCList.(2*n+1 -- 3*n) in
|
let l3 = CCList.(2*n+1 -- 3*n) in
|
||||||
let arg = l1, l2, l3 in
|
let arg = l1, l2, l3 in
|
||||||
B.throughputN time
|
B.throughputN time ~repeat
|
||||||
[ "CCList.append", append_ CCList.append, arg
|
[ "CCList.append", append_ CCList.append, arg
|
||||||
; "List.append", append_ List.append, arg
|
; "List.append", append_ List.append, arg
|
||||||
]
|
]
|
||||||
|
|
@ -58,7 +61,7 @@ module L = struct
|
||||||
(fun i x -> CCList.(x -- (x+ min i 100)))
|
(fun i x -> CCList.(x -- (x+ min i 100)))
|
||||||
CCList.(1 -- n)
|
CCList.(1 -- n)
|
||||||
in
|
in
|
||||||
B.throughputN time
|
B.throughputN time ~repeat
|
||||||
[ "CCList.flatten", CCList.flatten, l
|
[ "CCList.flatten", CCList.flatten, l
|
||||||
; "List.flatten", List.flatten, l
|
; "List.flatten", List.flatten, l
|
||||||
; "fold_right append", fold_right_append_, l
|
; "fold_right append", fold_right_append_, l
|
||||||
|
|
@ -103,7 +106,7 @@ module Vec = struct
|
||||||
|
|
||||||
let bench_map n =
|
let bench_map n =
|
||||||
let v = CCVector.init n (fun x->x) in
|
let v = CCVector.init n (fun x->x) in
|
||||||
B.throughputN 2
|
B.throughputN 2 ~repeat
|
||||||
[ "map", CCVector.map f, v
|
[ "map", CCVector.map f, v
|
||||||
; "map_push", map_push_ f, v
|
; "map_push", map_push_ f, v
|
||||||
; "map_push_cap", map_push_size_ f, v
|
; "map_push_cap", map_push_size_ f, v
|
||||||
|
|
@ -120,7 +123,7 @@ module Vec = struct
|
||||||
|
|
||||||
let bench_append n =
|
let bench_append n =
|
||||||
let v2 = CCVector.init n (fun x->n+x) in
|
let v2 = CCVector.init n (fun x->n+x) in
|
||||||
B.throughputN 2
|
B.throughputN 2 ~repeat
|
||||||
[ "append", try_append_ CCVector.append n v2, ()
|
[ "append", try_append_ CCVector.append n v2, ()
|
||||||
; "append_naive", try_append_ append_naive_ n v2, ()
|
; "append_naive", try_append_ append_naive_ n v2, ()
|
||||||
]
|
]
|
||||||
|
|
@ -165,7 +168,7 @@ module Cache = struct
|
||||||
] @ l
|
] @ l
|
||||||
else l
|
else l
|
||||||
in
|
in
|
||||||
B.throughputN 3 l
|
B.throughputN 3 l ~repeat
|
||||||
|
|
||||||
let () = B.Tree.register (
|
let () = B.Tree.register (
|
||||||
"cache" @>>>
|
"cache" @>>>
|
||||||
|
|
@ -270,7 +273,7 @@ module Tbl = struct
|
||||||
h
|
h
|
||||||
|
|
||||||
let bench_maps1 n =
|
let bench_maps1 n =
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
["phashtbl_add", (fun n -> ignore (phashtbl_add n)), n;
|
["phashtbl_add", (fun n -> ignore (phashtbl_add n)), n;
|
||||||
"hashtbl_add", (fun n -> ignore (hashtbl_add n)), n;
|
"hashtbl_add", (fun n -> ignore (hashtbl_add n)), n;
|
||||||
"ihashtbl_add", (fun n -> ignore (ihashtbl_add n)), n;
|
"ihashtbl_add", (fun n -> ignore (ihashtbl_add n)), n;
|
||||||
|
|
@ -373,7 +376,7 @@ module Tbl = struct
|
||||||
h
|
h
|
||||||
|
|
||||||
let bench_maps2 n =
|
let bench_maps2 n =
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
["phashtbl_replace", (fun n -> ignore (phashtbl_replace n)), n;
|
["phashtbl_replace", (fun n -> ignore (phashtbl_replace n)), n;
|
||||||
"hashtbl_replace", (fun n -> ignore (hashtbl_replace n)), n;
|
"hashtbl_replace", (fun n -> ignore (hashtbl_replace n)), n;
|
||||||
"ihashtbl_replace", (fun n -> ignore (ihashtbl_replace n)), n;
|
"ihashtbl_replace", (fun n -> ignore (ihashtbl_replace n)), n;
|
||||||
|
|
@ -463,7 +466,7 @@ module Tbl = struct
|
||||||
let h'''''' = icchashtbl_add n in
|
let h'''''' = icchashtbl_add n in
|
||||||
let ht = hashtrie_add n in
|
let ht = hashtrie_add n in
|
||||||
let hamt = hamt_add n in
|
let hamt = hamt_add n in
|
||||||
B.throughputN 3 [
|
B.throughputN 3 ~repeat [
|
||||||
"phashtbl_find", (fun () -> phashtbl_find h n), ();
|
"phashtbl_find", (fun () -> phashtbl_find h n), ();
|
||||||
"hashtbl_find", (fun () -> hashtbl_find h' n), ();
|
"hashtbl_find", (fun () -> hashtbl_find h' n), ();
|
||||||
"ihashtbl_find", (fun () -> ihashtbl_find h'' n), ();
|
"ihashtbl_find", (fun () -> ihashtbl_find h'' n), ();
|
||||||
|
|
@ -492,7 +495,7 @@ module Iter = struct
|
||||||
let seq () = Sequence.fold (+) 0 Sequence.(0 --n) in
|
let seq () = Sequence.fold (+) 0 Sequence.(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 () = CCKList.fold (+) 0 CCKList.(0 -- n) in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "sequence.fold", seq, ();
|
[ "sequence.fold", seq, ();
|
||||||
"gen.fold", gen, ();
|
"gen.fold", gen, ();
|
||||||
"klist.fold", klist, ();
|
"klist.fold", klist, ();
|
||||||
|
|
@ -509,7 +512,7 @@ module Iter = struct
|
||||||
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
|
B.throughputN 3 ~repeat
|
||||||
[ "sequence.flat_map", seq, ();
|
[ "sequence.flat_map", seq, ();
|
||||||
"gen.flat_map", gen, ();
|
"gen.flat_map", gen, ();
|
||||||
"klist.flat_map", klist, ();
|
"klist.flat_map", klist, ();
|
||||||
|
|
@ -532,7 +535,7 @@ module Iter = struct
|
||||||
1 -- n |> iter (fun x -> i := !i * x)
|
1 -- n |> iter (fun x -> i := !i * x)
|
||||||
)
|
)
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "sequence.iter", seq, ();
|
[ "sequence.iter", seq, ();
|
||||||
"gen.iter", gen, ();
|
"gen.iter", gen, ();
|
||||||
"klist.iter", klist, ();
|
"klist.iter", klist, ();
|
||||||
|
|
@ -595,7 +598,7 @@ module Batch = struct
|
||||||
CCPrint.printf "batch: %a\n" (CCArray.pp CCInt.pp) (batch a);
|
CCPrint.printf "batch: %a\n" (CCArray.pp CCInt.pp) (batch a);
|
||||||
*)
|
*)
|
||||||
assert (C.equal (batch a) (naive a));
|
assert (C.equal (batch a) (naive a));
|
||||||
B.throughputN time
|
B.throughputN time ~repeat
|
||||||
[ C.name ^ "_naive", naive, a
|
[ C.name ^ "_naive", naive, a
|
||||||
; C.name ^ "_batch", batch, a
|
; C.name ^ "_batch", batch, a
|
||||||
]
|
]
|
||||||
|
|
@ -778,7 +781,7 @@ module Deque = struct
|
||||||
D.iter (fun _ -> incr n) q;
|
D.iter (fun _ -> incr n) q;
|
||||||
()
|
()
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "base", make base, ()
|
[ "base", make base, ()
|
||||||
; "cur", make cur, ()
|
; "cur", make cur, ()
|
||||||
; "fqueue", make fqueue, ()
|
; "fqueue", make fqueue, ()
|
||||||
|
|
@ -789,7 +792,7 @@ module Deque = struct
|
||||||
let q = D.create() in
|
let q = D.create() in
|
||||||
for i=0 to n do D.push_front q i done
|
for i=0 to n do D.push_front q i done
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "base", make base, ()
|
[ "base", make base, ()
|
||||||
; "cur", make cur, ()
|
; "cur", make cur, ()
|
||||||
; "fqueue", make fqueue, ()
|
; "fqueue", make fqueue, ()
|
||||||
|
|
@ -801,7 +804,7 @@ module Deque = struct
|
||||||
fun () ->
|
fun () ->
|
||||||
for i=0 to n do D.push_back q i done
|
for i=0 to n do D.push_back q i done
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "base", make base, ()
|
[ "base", make base, ()
|
||||||
; "cur", make cur, ()
|
; "cur", make cur, ()
|
||||||
; "fqueue", make fqueue, ()
|
; "fqueue", make fqueue, ()
|
||||||
|
|
@ -814,7 +817,7 @@ module Deque = struct
|
||||||
let q2 = D.of_seq seq in
|
let q2 = D.of_seq seq in
|
||||||
fun () -> D.append_back ~into:q1 q2
|
fun () -> D.append_back ~into:q1 q2
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "base", make base, ()
|
[ "base", make base, ()
|
||||||
; "cur", make cur, ()
|
; "cur", make cur, ()
|
||||||
; "fqueue", make fqueue, ()
|
; "fqueue", make fqueue, ()
|
||||||
|
|
@ -826,7 +829,7 @@ module Deque = struct
|
||||||
let q = D.of_seq seq in
|
let q = D.of_seq seq in
|
||||||
fun () -> ignore (D.length q)
|
fun () -> ignore (D.length q)
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "base", make base, ()
|
[ "base", make base, ()
|
||||||
; "cur", make cur, ()
|
; "cur", make cur, ()
|
||||||
; "fqueue", make fqueue, ()
|
; "fqueue", make fqueue, ()
|
||||||
|
|
@ -894,7 +897,7 @@ module Thread = struct
|
||||||
assert (expected_res = CCLock.get res);
|
assert (expected_res = CCLock.get res);
|
||||||
()
|
()
|
||||||
in
|
in
|
||||||
B.throughputN 3
|
B.throughputN 3 ~repeat
|
||||||
[ "cur", make cur, ()
|
[ "cur", make cur, ()
|
||||||
; "naive", make naive, ()
|
; "naive", make naive, ()
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue