Skip to content

Instantly share code, notes, and snippets.

@dc-mak
Last active January 11, 2018 22:00
Show Gist options
  • Save dc-mak/27f13f15d1dee21281f0d88f28cbed9b to your computer and use it in GitHub Desktop.
Save dc-mak/27f13f15d1dee21281f0d88f28cbed9b to your computer and use it in GitHub Desktop.
Owl Perf Common (printing only times)
(* helper functions for performance test *)
(* test one operation c times, output the mean time *)
let test_op s c op =
let ttime = ref 0. in
for i = 1 to c do
Gc.compact ();
let t0 = Unix.gettimeofday () in
let _ = op () in
let t1 = Unix.gettimeofday () in
ttime := !ttime +. (t1 -. t0)
done;
ttime := if c = 0 then 0. else !ttime /. (float_of_int c);
(* Printf.printf "| %s :\t %.8fs \n" s !ttime; *)
Printf.printf "%.8f\n"!ttime;
flush stdout
(* test one operation c time, output the used time in each evaluation *)
let test_op_each c op =
(* Printf.printf "| test some fun %i times\n" c; *)
let ttime = ref 0. in
for i = 1 to c do
Gc.compact ();
let t0 = Unix.gettimeofday () in
let _ = op () in
let t1 = Unix.gettimeofday () in
(* Printf.printf "| #%0i\t:\t %.8fs \n" i (t1 -. t0); *)
flush stdout;
ttime := !ttime +. (t1 -. t0)
done;
ttime := if c = 0 then 0. else !ttime /. (float_of_int c);
(* Printf.printf "| avg.\t:\t %.8fs \n" !ttime *)
Printf.printf "%.8f\n" !ttime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment