| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Meter.Time
Description
Time measurement as a Circuit.
timeX is the canonical Meter for nanosecond timing. All other
time combinators are derived from it via meterAction.
Synopsis
- type Nanos = Integer
- nanos :: IO Nanos
- timeX :: Meter (K IO) Nanos Nanos
- tick :: (a -> b) -> a -> IO (Nanos, b)
- ticks :: Int -> (a -> b) -> a -> IO ([Nanos], b)
- ticksN :: Int -> (a -> b) -> a -> IO (Nanos, b)
- ticksION :: Int -> IO a -> IO (Nanos, a)
- meterIO :: forall a b (t :: Type -> Type -> Type). (a -> IO b) -> Trace t (K IO) a (Nanos, b)
- meter :: forall a b (t :: Type -> Type -> Type). (a -> b) -> Trace t (K IO) a (Nanos, b)
- warmup :: Int -> IO ()
- reifyC :: (Category arr, Traced (,) arr) => Trace (,) arr a b -> arr a b
- once :: Meter (K IO) a b -> (c -> d) -> c -> IO (b, d)
- onceK :: MonadFix m => Meter (K m) a b -> K m c d -> c -> m (b, d)
- timesK :: Int -> Int -> Meter (K IO) a b -> K IO c d -> K IO c ([b], d)
Time meter
Read the monotonic clock. Absolute value is not meaningful; use deltas between readings.
On Linux/macOS we use MonotonicRaw for NTP-frequency-adjustment-free
timing; on Windows we fall back to the portable Monotonic clock.
Single timing
tick :: (a -> b) -> a -> IO (Nanos, b) Source #
Single timing of a pure function. Returns (nanos, result).
Repeated timing
ticks :: Int -> (a -> b) -> a -> IO ([Nanos], b) Source #
n timings of the same function. Returns ( [nanos], lastResult ).
ticksN :: Int -> (a -> b) -> a -> IO (Nanos, b) Source #
n timings collapsed to a single average nanosecond count.
The computation is run n times; the total time is divided by n.
IO repeated timing
ticksION :: Int -> IO a -> IO (Nanos, a) Source #
n IO timings collapsed to a single average nanosecond count.
Plugin metering
meterIO :: forall a b (t :: Type -> Type -> Type). (a -> IO b) -> Trace t (K IO) a (Nanos, b) Source #
meter :: forall a b (t :: Type -> Type -> Type). (a -> b) -> Trace t (K IO) a (Nanos, b) Source #
Meter a pure function with timeX. Forces to WHNF inside the timed
bracket so the work cannot be floated out.
Warmup
Reify helper
Single-shot measurement runners
once :: Meter (K IO) a b -> (c -> d) -> c -> IO (b, d) Source #
Measure a single call to a pure function. Forces the result to WHNF
inside the timed IO action so the work cannot be floated out.
onceK :: MonadFix m => Meter (K m) a b -> K m c d -> c -> m (b, d) Source #
Measure a single call to a K arrow.
Repeated measurement runners
timesK :: Int -> Int -> Meter (K IO) a b -> K IO c d -> K IO c ([b], d) Source #
Measure a K arrow repeated n times. Returns per-run
measurements and the last result.
The step is marked NOINLINE so GHC cannot float the computation
out of the timing loop.
>>>import Circuit.Category (K(..))>>>import Circuit.Meter (Meter(..))>>>let m = Meter (K $ \_ -> pure 0) (K $ \_ -> pure 0)>>>runK (timesK 100 3 m (K (pure . (*2)))) 5([...,...,...],10)