Performance Timing
Hal Daume III
hdaume@ISI.EDU
Thu, 27 Mar 2003 07:19:29 -0800 (PST)
This is in part an answer, in part a question. If 'b' is a "simple
value", then somethign like:
timer f a = do
t1 <- get current time
t2 <- f a `seq` get current time
return (different in t2 and t1)
(my memory of Time fails right now, so fill in the proper functions.)
perhaps safer is to use DeepSeq, which has been cited a lot on this
list; i think you can find a copy at
http://www.isi.edu/~hdaume/haskell/Util/DeepSeq.hs and then replace `seq`
with `deepSeq`.
finally, another option (and here is my question, too), is:
timer f a = do
t1 <- get current time
evaluate (f a)
t2 <- get current time
return (different in t2 and t1)
where evaluate is from Control.Exception. could someone tell me how
evaluate compares to seq and deepSeq?
--
Hal Daume III | hdaume@isi.edu
"Arrest this man, he talks in maths." | www.isi.edu/~hdaume
On Thu, 27 Mar 2003, Spencer Janssen wrote:
> I've written two versions of a prime number sieve, and I'm trying to
> figure out how to performance test them. I've found functions to get
> the current date and time, and to subtract them, but when I put them in
> a do notation, I guess the laziness or something, makes the calculation
> happen first, then the two times are called, so I get almost 0
> difference between the two.
>
> I guess I'm looking for something like this:
> timer :: (a -> b) -> a -> IO TimeDiff
>
> Spencer Janssen
>
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>