@@ -21,7 +21,7 @@ import System.CPUTime
21
21
22
22
23
23
-- | CPU time with picosecond resolution
24
- newtype CPUTime = CPUTime Integer
24
+ newtype CPUTime = CPUTime Natural
25
25
26
26
27
27
instance NFData CPUTime where
@@ -50,40 +50,40 @@ instance Show CPUTime where
50
50
day = 24 * hour
51
51
52
52
53
- zeroPad :: Int -> Integer -> String
53
+ zeroPad :: Int -> Natural -> String
54
54
zeroPad k i = replicate (k - length shown) ' 0' <> shown
55
55
where
56
56
shown = show i
57
57
58
58
59
- timeOp :: MonadIO m => m a -> m (CPUTime , a )
59
+ timeOp :: ( MonadIO m , NFData a ) => m a -> m (CPUTime , a )
60
60
timeOp ioa = do
61
61
t1 <- liftIO getCPUTime
62
- a <- ioa
62
+ a <- force <$> ioa
63
63
t2 <- liftIO getCPUTime
64
- let t = CPUTime ( t2 - t1)
64
+ let t = CPUTime . fromIntegral $ t2 - t1
65
65
pure (t, a)
66
66
67
67
68
68
fromPicoseconds :: Natural -> CPUTime
69
- fromPicoseconds = CPUTime . toInteger
69
+ fromPicoseconds = CPUTime
70
70
71
71
72
72
fromMicroseconds :: Natural -> CPUTime
73
- fromMicroseconds = CPUTime . (* 1000000000 ) . toInteger
73
+ fromMicroseconds = CPUTime . (* 1000000 )
74
74
75
75
76
76
fromMilliseconds :: Natural -> CPUTime
77
- fromMilliseconds = CPUTime . (* 1000000 ) . toInteger
77
+ fromMilliseconds = CPUTime . (* 1000000000 )
78
78
79
79
80
80
toPicoseconds :: CPUTime -> Natural
81
- toPicoseconds (CPUTime x) = fromInteger x
81
+ toPicoseconds (CPUTime x) = x
82
82
83
83
84
84
toMicroseconds :: CPUTime -> Natural
85
- toMicroseconds (CPUTime x) = fromInteger $ x `div` 1000000
85
+ toMicroseconds (CPUTime x) = x `div` 1000000
86
86
87
87
88
88
toMilliseconds :: CPUTime -> Natural
89
- toMilliseconds (CPUTime x) = fromInteger $ x `div` 1000000000
89
+ toMilliseconds (CPUTime x) = x `div` 1000000000
0 commit comments