[Haskell] timing/timeout (how to express that in Haskell)
Bulat Ziganshin
bulat.ziganshin at gmail.com
Fri May 12 09:42:28 EDT 2006
Hello Mirko,
Friday, May 12, 2006, 4:42:02 PM, you wrote:
>> PS: I am still curious: does threadDelay use
>> the wall clock or the per-process clock (CPU time)?
> I think it uses wall clock time. Proof:
>> And regardless of the answer - how could one obtain
>> the opposite behaviour? (I don't find this discussed
>> in the visible docs. Or am I missing something?)
use threadDelay in cycle, testing CPU time each time. the following
code used by me to measure both wall and CPU time. but i should say
that cpu time measurement sometimes gives negative results :) i think
it may be because it returns time for CURRENT OS thread, but Haskell
runtime sometimes creates new OS thread and continue execute Haskell
code in this new created thread (at least under Windows)
benchmark h str times action = do
prev <- getCPUTime
prev2 <- getClockTime
action
current <- getCPUTime
current2 <- getClockTime
let secs = fromIntegral (current-prev) / 1e12
secs2 = diffTimes current2 prev2
putStrLn$ str ++ ": " ++ showTime secs2 ++ " (user: " ++ showTime secs ++ ")"
showTime secs = showFFloat (Just 3) secs " secs"
diffTimes (TOD sa pa) (TOD sb pb) = i(sa - sb) + (i(pa-pb) / 1e12)
i x = fromIntegral x
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell
mailing list