[Haskell-cafe] newbie timing question

Sean McLaughlin seanmcl at cmu.edu
Fri Jan 26 17:56:21 EST 2007


I'm trying to write a simple function to time an application.

-- this doesn't work

time f x =
   do n1 <- CPUTime.getCPUTime
      let res = f x in
        do n2 <- CPUTime.getCPUTime
           return (res,n2 - n1)

On a function that takes 8 seconds to complete, returns

According to the documentation, this time is in picoseconds, making
this 46 microseconds.

I also tried

-- neither does this

time' f x =
   do n1 <- Time.getClockTime
      let res = f x in
        do n2 <- Time.getClockTime
           return (res,Time.diffClockTimes n2 n1)

It returns something on that scale for picoseconds.
How can I get a rough wall clock timing of functions?



More information about the Haskell-Cafe mailing list