caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Sven Luther <luther@dpt-info.u-strasbg.fr>
To: onlyclimb <onlyclimb@163.com>
Cc: Chris Hecker <checker@d6.com>, caml-list@inria.fr
Subject: Re: [Caml-list] time function
Date: Mon, 23 Dec 2002 09:19:34 +0100	[thread overview]
Message-ID: <20021223081934.GA1549@iliana> (raw)
In-Reply-To: <3E073459.1000100@163.com>

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


  reply	other threads:[~2002-12-23  8:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-23 15:18 onlyclimb
2002-12-23  7:38 ` Chris Hecker
2002-12-23 16:05   ` onlyclimb
2002-12-23  8:19     ` Sven Luther [this message]
2002-12-23  8:51       ` David Brown
2002-12-23 17:13       ` onlyclimb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021223081934.GA1549@iliana \
    --to=luther@dpt-info.u-strasbg.fr \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    --cc=onlyclimb@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).