@@ -21,7 +21,7 @@ import System.CPUTime
2121
2222
2323-- | CPU time with picosecond resolution
24- newtype CPUTime = CPUTime Integer
24+ newtype CPUTime = CPUTime Natural
2525
2626
2727instance NFData CPUTime where
@@ -50,40 +50,40 @@ instance Show CPUTime where
5050 day = 24 * hour
5151
5252
53- zeroPad :: Int -> Integer -> String
53+ zeroPad :: Int -> Natural -> String
5454zeroPad k i = replicate (k - length shown) ' 0' <> shown
5555 where
5656 shown = show i
5757
5858
59- timeOp :: MonadIO m => m a -> m (CPUTime , a )
59+ timeOp :: ( MonadIO m , NFData a ) => m a -> m (CPUTime , a )
6060timeOp ioa = do
6161 t1 <- liftIO getCPUTime
62- a <- ioa
62+ a <- force <$> ioa
6363 t2 <- liftIO getCPUTime
64- let t = CPUTime ( t2 - t1)
64+ let t = CPUTime . fromIntegral $ t2 - t1
6565 pure (t, a)
6666
6767
6868fromPicoseconds :: Natural -> CPUTime
69- fromPicoseconds = CPUTime . toInteger
69+ fromPicoseconds = CPUTime
7070
7171
7272fromMicroseconds :: Natural -> CPUTime
73- fromMicroseconds = CPUTime . (* 1000000000 ) . toInteger
73+ fromMicroseconds = CPUTime . (* 1000000 )
7474
7575
7676fromMilliseconds :: Natural -> CPUTime
77- fromMilliseconds = CPUTime . (* 1000000 ) . toInteger
77+ fromMilliseconds = CPUTime . (* 1000000000 )
7878
7979
8080toPicoseconds :: CPUTime -> Natural
81- toPicoseconds (CPUTime x) = fromInteger x
81+ toPicoseconds (CPUTime x) = x
8282
8383
8484toMicroseconds :: CPUTime -> Natural
85- toMicroseconds (CPUTime x) = fromInteger $ x `div` 1000000
85+ toMicroseconds (CPUTime x) = x `div` 1000000
8686
8787
8888toMilliseconds :: CPUTime -> Natural
89- toMilliseconds (CPUTime x) = fromInteger $ x `div` 1000000000
89+ toMilliseconds (CPUTime x) = x `div` 1000000000
0 commit comments