Skip to content

Instantly share code, notes, and snippets.

@c-cube
Created February 27, 2013 19:21
Show Gist options
  • Save c-cube/5050808 to your computer and use it in GitHub Desktop.
Save c-cube/5050808 to your computer and use it in GitHub Desktop.
Benchmark Sequence.t against ExtLib's Enum.t
open ExtLib
(* sum of the ints in the list *)
let sum_list_seq l =
Sequence.fold (+) 0 (Sequence.of_list l)
(* sum of the ints in the list *)
let sum_list_enum l =
Enum.fold (+) 0 (List.enum l)
let make_list n =
Sequence.to_list (Sequence.int_range ~start:0 ~stop:n)
let measure_time f x =
let start = Unix.gettimeofday () in
let y = f x in
let stop = Unix.gettimeofday () in
y, stop -. start
let _ =
let n = int_of_string Sys.argv.(1) in
Format.printf "compare sum on lists of size %d@." n;
let l = make_list n in
Format.printf "list created, length %d@." (List.length l);
let x1, time_seq = measure_time sum_list_seq l in
let x2, time_enum = measure_time sum_list_enum l in
assert (x1 = x2);
Format.printf "time seq: %.3f, time enum: %.3f@." time_seq time_enum
(* ocamlfind ocamlopt -I `ocamlfind query sequence` -I `ocamlfind query extlib`
sequence.cmxa extLib.cmxa unix.cmxa bench.ml -o bench *)
@c-cube
Copy link
Author

c-cube commented Feb 27, 2013

Compile it, then run it on some integer value (length of list)

./bench 1000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment