Loading ...
Sorry, an error occurred while loading the content.

11708Re: "ocaml_beginners"::[] timer?

Expand Messages
  • markwvh
    Jan 3, 2010
      --- In ocaml_beginners@yahoogroups.com, Jon Harrop <jon@...> wrote:
      >
      > On Saturday 02 January 2010 22:42:07 Jamie Morgenstern wrote:
      > > Hello;
      > >
      > > I was wondering if there is a more fine-grained mechanism for timing
      > > code's runtime (e.g., Time.start(timer) ... code ... Time.end(timer) that
      > > will calculate only the time spent between the start and end calls.
      > >
      > > I know this exists in ML; hoping similar is here.
      > >
      > > Thanks!
      >
      > Unix.gettimeofday()?
      >

      Yeah. I tend to use something like this:

      let time_and_res (thunk:unit -> 'a) : (float * 'a) =
      let t = Unix.gettimeofday() in
      let r = thunk() in
      let t' = Unix.gettimeofday() in
      (t' -. t, r)

      HTH.
      -m
    • Show all 3 messages in this topic