* [Caml-list] time function @ 2002-12-23 15:18 onlyclimb 2002-12-23 7:38 ` Chris Hecker 0 siblings, 1 reply; 6+ messages in thread From: onlyclimb @ 2002-12-23 15:18 UTC (permalink / raw) To: caml-list It seems that Sys.time() and Unix.time() both produce a time resolution of seconds How can i get a resolution of milli-seconds thanks ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] time function 2002-12-23 15:18 [Caml-list] time function onlyclimb @ 2002-12-23 7:38 ` Chris Hecker 2002-12-23 16:05 ` onlyclimb 0 siblings, 1 reply; 6+ messages in thread From: Chris Hecker @ 2002-12-23 7:38 UTC (permalink / raw) To: onlyclimb, caml-list >How can i get a resolution of milli-seconds Unix.gettimeofday, I believe. This is in the documentation. Chris ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] time function 2002-12-23 7:38 ` Chris Hecker @ 2002-12-23 16:05 ` onlyclimb 2002-12-23 8:19 ` Sven Luther 0 siblings, 1 reply; 6+ messages in thread From: onlyclimb @ 2002-12-23 16:05 UTC (permalink / raw) To: Chris Hecker, caml-list Chris Hecker wrote: > >> How can i get a resolution of milli-seconds > > > Unix.gettimeofday, I believe. This is in the documentation. > > > # open Unix;; # time();; - : float = 1040659293. # gettimeofday();; - : float = 1040659299.94 it seems that gettimeofday() is for centi-second, :-) ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] time function 2002-12-23 16:05 ` onlyclimb @ 2002-12-23 8:19 ` Sven Luther 2002-12-23 8:51 ` David Brown 2002-12-23 17:13 ` onlyclimb 0 siblings, 2 replies; 6+ messages in thread From: Sven Luther @ 2002-12-23 8:19 UTC (permalink / raw) To: onlyclimb; +Cc: Chris Hecker, caml-list On Mon, Dec 23, 2002 at 04:05:45PM +0000, onlyclimb wrote: > Chris Hecker wrote: > > > > >>How can i get a resolution of milli-seconds > > > > > >Unix.gettimeofday, I believe. This is in the documentation. > > > > > > > # open Unix;; > # time();; > - : float = 1040659293. > # gettimeofday();; > - : float = 1040659299.94 > it seems that gettimeofday() is for centi-second, :-) This code : let string_of_time t = let d = truncate (t /. 86400.) in let rd = t -. (float_of_int (d*86400)) in let h = truncate (rd /. 3600.) in let rh = rd -. (float_of_int (h*3600)) in let m = truncate (rh /. 60.) in let rm = rh -. (float_of_int (m*60)) in let s = truncate rm in let rs = rm -. (float_of_int s) in let ms = truncate (rs *. 1000.) in let rms = rs -. ((float_of_int ms)/.1000.) in let mms = truncate (rms *. 1000000.) in Printf.sprintf "%d days, %d hours, %d minutes, %d seconds, %d milliseconds, %d microseconds" d h m s ms mms and later : let xxx,yyy,aaa = ref 0.0, ref 0.0, ref l in xxx := Unix.gettimeofday (); aaa := (* Some calculation *); yyy := Unix.gettimeofday (); let time_used = (!yyy -. !xxx) in Printf.printf "Time used : %f seconds \n" time_used; Printf.printf "Time used : %s\n" (string_of_time time_used); Yields : Time used : 0.035280 seconds Time used : 0 days, 0 hours, 0 minutes, 0 seconds, 35 milliseconds, 279 microseconds So i guess it works with milliseconds, but i may be wrong. It may just be a coincidence that your call to gettimeofday fall on a full centi-second, and thus the last decimal was not shown. Friendly, Sven Luthr > > > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: > http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: > http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] time function 2002-12-23 8:19 ` Sven Luther @ 2002-12-23 8:51 ` David Brown 2002-12-23 17:13 ` onlyclimb 1 sibling, 0 replies; 6+ messages in thread From: David Brown @ 2002-12-23 8:51 UTC (permalink / raw) To: Sven Luther; +Cc: onlyclimb, Chris Hecker, caml-list On Mon, Dec 23, 2002 at 09:19:34AM +0100, Sven Luther wrote: > > - : float = 1040659299.94 > > it seems that gettimeofday() is for centi-second, :-) > It may just be a coincidence that your call to gettimeofday fall on a > full centi-second, and thus the last decimal was not shown. Actually, it's just the default resolution of the float pretty-printer in the top-level. # Printf.printf "%.30f\n" (Unix.gettimeofday ());; 1040633442.482807993888854980468750000000 - : unit = () Will give you many more digits than are actually meaningful. Dave Brown ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] time function 2002-12-23 8:19 ` Sven Luther 2002-12-23 8:51 ` David Brown @ 2002-12-23 17:13 ` onlyclimb 1 sibling, 0 replies; 6+ messages in thread From: onlyclimb @ 2002-12-23 17:13 UTC (permalink / raw) To: Sven Luther, caml-list > > >Time used : 0.035280 seconds >Time used : 0 days, 0 hours, 0 minutes, 0 seconds, 35 milliseconds, 279 microseconds > >So i guess it works with milliseconds, but i may be wrong. > >It may just be a coincidence that your call to gettimeofday fall on a >full centi-second, and thus the last decimal was not shown. > oh. i see. maybe it is because on the top level it only show 12 digit. so i can not see the digits after centisecond. # (let a = gettimeofday() in for i=0 to 10000 do ignore (i=i) done ; gettimeofday() -. a ) ;; - : float = 0.00056004524231 # for i =0 to 10000 do print_float ((gettimeofday()); print_string " " done;; ...... 63452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 1040663452.51 - : unit = () Thanks Merry Christmas climb ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-12-23 9:13 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-12-23 15:18 [Caml-list] time function onlyclimb 2002-12-23 7:38 ` Chris Hecker 2002-12-23 16:05 ` onlyclimb 2002-12-23 8:19 ` Sven Luther 2002-12-23 8:51 ` David Brown 2002-12-23 17:13 ` onlyclimb
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox