Created
February 27, 2013 19:21
-
-
Save c-cube/5050808 to your computer and use it in GitHub Desktop.
Benchmark Sequence.t against ExtLib's Enum.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile it, then run it on some integer value (length of list)
./bench 1000000