speed.ml 1.14 KB
Newer Older
POTTIER Francois's avatar
POTTIER Francois committed
1 2
open Printf

POTTIER Francois's avatar
POTTIER Francois committed
3
(* Read one floating-point number in a file. *)
POTTIER Francois's avatar
POTTIER Francois committed
4 5 6 7 8 9 10 11 12 13 14 15
let read f =
  let c = open_in f in
  let s = input_line c in
  close_in c;
  float_of_string s

let dry =
  read "gene/dry.time"
let code =
  read "gene/code.time"
let table =
  read "gene/table.time"
16 17 18 19 20 21 22 23
let ocamlyacc =
  try
    Some (read "gene/ocamlyacc.time")
  with Sys_error _ ->
    None

let optionally o f =
  match o with Some x -> f x | None -> ()
POTTIER Francois's avatar
POTTIER Francois committed
24 25 26 27 28

let () =
  printf "Test input generation takes %.2f seconds.\n" dry;
  printf "Parsing with the code back-end takes %.2f seconds.\n" (code -. dry);
  printf "Parsing with the table back-end takes %.2f seconds.\n" (table -. dry);
29 30 31
  optionally ocamlyacc (fun ocamlyacc ->
    printf "Parsing with ocamlyacc takes %.2f seconds.\n" (ocamlyacc -. dry);
  );
POTTIER Francois's avatar
POTTIER Francois committed
32
  printf "The table back-end is %.1f times slower than the code back-end.\n" ((table -. dry) /. (code -. dry));
33 34 35 36
  optionally ocamlyacc (fun ocamlyacc ->
    printf "ocamlyacc is %.1f times slower than the code back-end.\n" ((ocamlyacc -. dry) /. (code -. dry));
    printf "ocamlyacc is %.1f times faster than the table back-end.\n" ((table -. dry) /. (ocamlyacc -. dry));
  );
POTTIER Francois's avatar
POTTIER Francois committed
37 38
  flush stdout