From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA29027; Mon, 23 Dec 2002 09:21:17 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA29257 for ; Mon, 23 Dec 2002 09:21:14 +0100 (MET) Received: from mel-rto4.wanadoo.fr (smtp-out-4.wanadoo.fr [193.252.19.23]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gBN8LBn13373 for ; Mon, 23 Dec 2002 09:21:14 +0100 (MET) Received: from mel-rta9.wanadoo.fr (193.252.19.69) by mel-rto4.wanadoo.fr (6.7.015) id 3E01656F0021D615; Mon, 23 Dec 2002 09:19:35 +0100 Received: from iliana (81.48.190.7) by mel-rta9.wanadoo.fr (6.7.015) id 3E016475001EC311; Mon, 23 Dec 2002 09:19:35 +0100 Received: from luther by iliana with local (Exim 3.36 #1 (Debian)) id 18QNoE-0000Q8-00; Mon, 23 Dec 2002 09:19:34 +0100 Date: Mon, 23 Dec 2002 09:19:34 +0100 To: onlyclimb Cc: Chris Hecker , caml-list@inria.fr Subject: Re: [Caml-list] time function Message-ID: <20021223081934.GA1549@iliana> References: <4.3.2.7.2.20021222233716.030c1be0@localhost> <3E073459.1000100@163.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3E073459.1000100@163.com> User-Agent: Mutt/1.4i From: Sven Luther Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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