mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-08 04:05:30 -05:00
benchmark list.map
This commit is contained in:
parent
f685303a32
commit
96c62d9048
1 changed files with 26 additions and 1 deletions
|
|
@ -16,6 +16,25 @@ let repeat = 3
|
||||||
let (%%) f g x = f (g x)
|
let (%%) f g x = f (g x)
|
||||||
|
|
||||||
module L = struct
|
module L = struct
|
||||||
|
(* MAP *)
|
||||||
|
|
||||||
|
let f_ x = x+1
|
||||||
|
|
||||||
|
let bench_map ?(time=2) n =
|
||||||
|
let l = CCList.(1 -- n) in
|
||||||
|
let ral = CCRAL.of_list l in
|
||||||
|
let map_naive () = ignore (try List.map f_ l with Stack_overflow -> [])
|
||||||
|
and map_tailrec () = ignore (List.rev (List.rev_map f_ l))
|
||||||
|
and ccmap () = ignore (CCList.map f_ l)
|
||||||
|
and ralmap () = ignore (CCRAL.map f_ ral)
|
||||||
|
in
|
||||||
|
B.throughputN time ~repeat
|
||||||
|
[ "List.map", map_naive, ()
|
||||||
|
; "List.rev_map o rev", map_tailrec, ()
|
||||||
|
; "CCList.map", ccmap, ()
|
||||||
|
; "CCRAL.map", ralmap, ()
|
||||||
|
]
|
||||||
|
|
||||||
(* FLAT MAP *)
|
(* FLAT MAP *)
|
||||||
|
|
||||||
let f_ x =
|
let f_ x =
|
||||||
|
|
@ -72,7 +91,13 @@ module L = struct
|
||||||
|
|
||||||
let () = B.Tree.register (
|
let () = B.Tree.register (
|
||||||
"list" @>>>
|
"list" @>>>
|
||||||
[ "flat_map" @>>
|
[ "map" @>>
|
||||||
|
B.Tree.concat
|
||||||
|
[ app_int (bench_map ~time:2) 100
|
||||||
|
; app_int (bench_map ~time:2) 10_000
|
||||||
|
; app_int (bench_map ~time:4) 100_000
|
||||||
|
; app_int (bench_map ~time:4) 500_000 ]
|
||||||
|
; "flat_map" @>>
|
||||||
B.Tree.concat
|
B.Tree.concat
|
||||||
[ app_int (bench_flat_map ~time:2) 100
|
[ app_int (bench_flat_map ~time:2) 100
|
||||||
; app_int (bench_flat_map ~time:2) 10_000
|
; app_int (bench_flat_map ~time:2) 10_000
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue