perf-0.8.0: Low-level run time measurement.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Perf.Measure

Description

Specification of a performance measurement type suitable for the PerfT monad transformer.

Synopsis

Documentation

data Measure m b Source #

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)

Constructors

forall a.Num b => Measure 

Fields

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)

count :: Measure IO Int Source #

a Measure used to count iterations

>>> r <- runMeasure count (pure ())
>>> r
(1,())

cycles :: Measure IO Cycle Source #

a Measure using the rdtsc CPU register (units are in cycles)

>>> r <- runMeasureN 1000 cycles (pure ())
(120540,()) -- ghci-level
(18673,())  -- compiled with -O2