From d2c7ea6ec2133836bf1ec756a53bf504f1c19a2b Mon Sep 17 00:00:00 2001 From: letouzey Date: Fri, 5 Oct 2012 11:22:01 +0000 Subject: More accurate timings for "Time foo" The elapsed time in seconds was computed via a difference of Unix.time(), but these Unix.time() aren't precise enough (just a number of seconds), and a difference is hence even less precise. We now use Unix.gettimeofday, and round the time difference to the millisecond. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@15858 85f007b7-540e-0410-9357-904b9bb8a0f7 --- lib/system.ml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/system.ml b/lib/system.ml index 6076217b30..84706d0313 100644 --- a/lib/system.ml +++ b/lib/system.ml @@ -198,15 +198,18 @@ let connect writefun readfun com = type time = float * float * float let get_time () = - let t = times () in - (time(), t.tms_utime, t.tms_stime) + let t = Unix.times () in + (Unix.gettimeofday(), t.tms_utime, t.tms_stime) -let time_difference (t1,_,_) (t2,_,_) = t2 -. t1 +(* Keep only 3 significant digits *) +let round f = (floor (f *. 1e3)) *. 1e-3 + +let time_difference (t1,_,_) (t2,_,_) = round (t2 -. t1) let fmt_time_difference (startreal,ustart,sstart) (stopreal,ustop,sstop) = - real (stopreal -. startreal) ++ str " secs " ++ + real (round (stopreal -. startreal)) ++ str " secs " ++ str "(" ++ - real ((-.) ustop ustart) ++ str "u" ++ + real (round (ustop -. ustart)) ++ str "u" ++ str "," ++ - real ((-.) sstop sstart) ++ str "s" ++ + real (round (sstop -. sstart)) ++ str "s" ++ str ")" -- cgit v1.2.3