1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
(* This is a typical problem where the functions are so fast (on a
2Ghz machine) that it takes way too long to get results. Thus a
wrapping in a loop is done. *)
let n = 100
let string_of_month1 =
let month = [| "Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug";
"Sep"; "Oct"; "Nov"; "Dec" |] in
fun i -> Array.unsafe_get month i
let f1 () =
for i = 1 to n do ignore(string_of_month1 7) done
let string_of_month2 = function
| 0 -> "Jan"
| 1 -> "Feb"
| 2 -> "Mar"
| 3 -> "Apr"
| 4 -> "May"
| 5 -> "Jun"
| 6 -> "Jul"
| 7 -> "Aug"
| 8 -> "Sep"
| 9 -> "Oct"
| 10 -> "Nov"
| 11 -> "Dec"
| _ -> failwith "h"
let f2 () =
for i = 1 to n do ignore(string_of_month2 7) done
open Benchmark
let () =
let res = throughputN 3 ~repeat:5 [ ("arr", f1, ());
("pat", f2, ()); ] in
tabulate res
|