mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add benchmark
This commit is contained in:
parent
635855b68b
commit
783f6020d6
1 changed files with 8 additions and 0 deletions
|
|
@ -20,16 +20,24 @@ module L = struct
|
||||||
|
|
||||||
let f_ x = x+1
|
let f_ x = x+1
|
||||||
|
|
||||||
|
let rec map_naive f l = match l with
|
||||||
|
| [] -> []
|
||||||
|
| x :: tail ->
|
||||||
|
let y = f x in
|
||||||
|
y :: map_naive f tail
|
||||||
|
|
||||||
let bench_map ?(time=2) n =
|
let bench_map ?(time=2) n =
|
||||||
let l = CCList.(1 -- n) in
|
let l = CCList.(1 -- n) in
|
||||||
let ral = CCRAL.of_list l in
|
let ral = CCRAL.of_list l in
|
||||||
let map_naive () = ignore (try List.map f_ l with Stack_overflow -> [])
|
let map_naive () = ignore (try List.map f_ l with Stack_overflow -> [])
|
||||||
|
and map_naive2 () = ignore (try map_naive f_ l with Stack_overflow -> [])
|
||||||
and map_tailrec () = ignore (List.rev (List.rev_map f_ l))
|
and map_tailrec () = ignore (List.rev (List.rev_map f_ l))
|
||||||
and ccmap () = ignore (CCList.map f_ l)
|
and ccmap () = ignore (CCList.map f_ l)
|
||||||
and ralmap () = ignore (CCRAL.map ~f:f_ ral)
|
and ralmap () = ignore (CCRAL.map ~f:f_ ral)
|
||||||
in
|
in
|
||||||
B.throughputN time ~repeat
|
B.throughputN time ~repeat
|
||||||
[ "List.map", map_naive, ()
|
[ "List.map", map_naive, ()
|
||||||
|
; "List.map(inline)", map_naive2, ()
|
||||||
; "List.rev_map o rev", map_tailrec, ()
|
; "List.rev_map o rev", map_tailrec, ()
|
||||||
; "CCList.map", ccmap, ()
|
; "CCList.map", ccmap, ()
|
||||||
; "CCRAL.map", ralmap, ()
|
; "CCRAL.map", ralmap, ()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue