module System.Clock.TimeIt where
import System.Clock
#if !MIN_VERSION_clock(0,7,0)
s2ns :: Num a => a
s2ns = 10^(9 :: Int)
toNanoSecs :: TimeSpec -> Integer
toNanoSecs (TimeSpec (toInteger -> s) (toInteger -> n)) = s * s2ns + n
#endif
elapsedTime :: IO a -> IO (a, Double)
elapsedTime action = do
startTime <- getTime Monotonic
r <- action
endTime <- getTime Monotonic
let result = diffSeconds endTime startTime
return (r, result)
diffSeconds :: TimeSpec -> TimeSpec -> Double
diffSeconds end start
= (* 1e-9)
$ fromIntegral
$ toNanoSecs end toNanoSecs start