Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Specification of a performance measurement type suitable for the PerfT
monad transformer.
Synopsis
- data Measure m b = forall a.Num b => Measure {}
- runMeasure :: Monad m => Measure m b -> m a -> m (b, a)
- runMeasureN :: Monad m => Int -> Measure m b -> m a -> m (b, a)
- cost :: Monad m => Measure m b -> m b
- cputime :: Measure IO Integer
- realtime :: Measure IO Double
- count :: Measure IO Int
- cycles :: Measure IO Cycle
Documentation
A Measure consists of a monadic effect prior to measuring, a monadic effect to finalise the measurement, and the value measured
For example, the measure specified below will return 1 every time measurement is requested, thus forming the base of a simple counter for loopy code.
>>>
let count = Measure 0 (pure ()) (pure 1)
runMeasure :: Monad m => Measure m b -> m a -> m (b, a) Source #
Measure a single effect.
>>>
r <- runMeasure count (pure "joy")
>>>
r
(1,"joy")
runMeasureN :: Monad m => Int -> Measure m b -> m a -> m (b, a) Source #
Measure once, but run an effect multiple times.
>>>
r <- runMeasureN 1000 count (pure "joys")
>>>
r
(1,"joys")
cost :: Monad m => Measure m b -> m b Source #
cost of a measurement in terms of the Measure's own units
>>>
r <- cost count
>>>
r
1
cputime :: Measure IO Integer Source #
a measure using getCPUTime
from System.CPUTime (unit is picoseconds)
>>>
r <- runMeasure cputime (pure $ foldl' (+) 0 [0..1000])
(34000000,500500)
realtime :: Measure IO Double Source #
a measure using getCurrentTime
(unit is seconds)
>>>
r <- runMeasure realtime (pure $ foldl' (+) 0 [0..1000])
(0.000046,500500)