<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/12/21ac3eedf24975c6cbca3646f48109dc"
  from="Sven Luther &lt;luther@d...&gt;"
  author="Sven Luther"
  date="2002-12-23T08:21:17"
  subject="Re: [Caml-list] time function"
  prev="2002/12/85b645315511ed17dcc3577d643c66b4"
  next="2002/12/21630feed7c539b7d0681b465c79f97b"
  prev-in-thread="2002/12/f4734b657369b00650069d2bbf5d2677"
  next-in-thread="2002/12/9a17a0866459c3a03977c601d7a0c746"
  prev-thread="2002/12/7b41bb2cf02f08cdbe03c5ca5733063b"
  next-thread="2002/12/85b645315511ed17dcc3577d643c66b4"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] time function">
<msg 
  url="2002/12/760539af03625c1d2af3b423714355e5"
  from="onlyclimb &lt;onlyclimb@1...&gt;"
  author="onlyclimb"
  date="2002-12-23T07:21:13"
  subject="[Caml-list] time function">
<msg 
  url="2002/12/e48c462e89c59263f9e15b37bf536ab9"
  from="Chris Hecker &lt;checker@d...&gt;"
  author="Chris Hecker"
  date="2002-12-23T07:40:42"
  subject="Re: [Caml-list] time function">
<msg 
  url="2002/12/f4734b657369b00650069d2bbf5d2677"
  from="onlyclimb &lt;onlyclimb@1...&gt;"
  author="onlyclimb"
  date="2002-12-23T08:06:04"
  subject="Re: [Caml-list] time function">
<msg 
  url="2002/12/21ac3eedf24975c6cbca3646f48109dc"
  from="Sven Luther &lt;luther@d...&gt;"
  author="Sven Luther"
  date="2002-12-23T08:21:17"
  subject="Re: [Caml-list] time function">
<msg 
  url="2002/12/9a17a0866459c3a03977c601d7a0c746"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2002-12-23T08:52:46"
  subject="Re: [Caml-list] time function">
</msg>
<msg 
  url="2002/12/9e50d6b9dc4fa4946c0dddc131ee2235"
  from="onlyclimb &lt;onlyclimb@1...&gt;"
  author="onlyclimb"
  date="2002-12-23T09:13:13"
  subject="Re: [Caml-list] time function">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
On Mon, Dec 23, 2002 at 04:05:45PM +0000, onlyclimb wrote:
&gt; Chris Hecker wrote:
&gt; 
&gt; &gt;
&gt; &gt;&gt;How can i get a resolution of milli-seconds
&gt; &gt;
&gt; &gt;
&gt; &gt;Unix.gettimeofday, I believe.  This is in the documentation.
&gt; &gt;
&gt; &gt;
&gt; &gt;
&gt; # open Unix;;
&gt; # time();;
&gt; - : float = 1040659293.
&gt; # gettimeofday();;
&gt; - : float = 1040659299.94
&gt; 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




&gt; 
&gt; 
&gt; -------------------
&gt; To unsubscribe, mail caml-list-request@inria.fr Archives: 
&gt; http://caml.inria.fr
&gt; Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: 
&gt; http://caml.inria.fr/FAQ/
&gt; 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

</contents>

</message>

