Last active
October 7, 2015 05:02
-
-
Save jyc/dc6d8a771bc472bfd868 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| let times = Hashtbl.create 1 | |
| let time_start' ht id = | |
| let (sum, _, n) = | |
| if Hashtbl.mem ht id then Hashtbl.find ht id | |
| else (0., 0., 0) in | |
| Hashtbl.replace ht id (sum, Sys.time (), n) | |
| let time_start = time_start' times | |
| let time_end' ht id = | |
| if not (Hashtbl.mem ht id) then failwith "invalid state!" | |
| else | |
| let (sum, last, n) = Hashtbl.find ht id in | |
| let (sum', last', n') = (sum +. (Sys.time () -. last), 0., n + 1) in | |
| Hashtbl.replace ht id (sum', last', n') | |
| let time_end = time_end' times | |
| let print_times () = | |
| print_endline "=== TIMES ===" ; | |
| let print_time id (sum, last, n) = | |
| let avg = sum /. (float_of_int n) in | |
| Printf.printf "[%s] average time: %f, number of times: %d\n" id avg n | |
| in | |
| Hashtbl.iter print_time times | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment