Module Unmark.Measurement

module Measurement: sig .. end

Low-level measurement machinery.


A probe provides a set of measurements, called counters. These are assumed to be global, monotonically increasing, and (ideally) affected by running code.

A single measurement is performed by invoking a probe to get the values of counters, running the target piece of code a certain number of times, getting the counters again, and reporting the difference.

The measurement process collects a series of measurements while varying the number of times the target code is ran.

module Probe: sig .. end

Probe construction and manipulation.

type runnable 

runnable is the object of measurement.

val runnable : (unit -> 'a) -> runnable
type sample = float array 

An array of counter values.

val sample : probe:Probe.probe ->
iters:int -> runnable -> sample

sample ~probe ~iters r performs a single measurement of r and returns a sample s.

It runs r in a tight loop iters times, returning the probe's counters' difference before and after the run.

s has core counters in the initial positions, followed by the probe's counters as given by Probe.counters probe. In particular, s.(0) = iters.

val measure : ?probe:Probe.probe ->
?min_t:float ->
?min_s:int -> runnable -> sample list

measure ~probe ~min_t ~min_s r performs a series of measurements of r.

Individual measurements are obtained by invoking sample with varying iters, until both the minimal number of samples are collected, and the minimal measurement time elapses.

probe is the probe used to produce measurements. Default nothing.

min_t is the minimal measurement time in seconds. Default 1.

min_s is the minimal number of samples to collect. Default 10.

The exact sampling strategy is not part of the API and could change. Currently, it's an exponential function with slow start, approximating iters -> iters^1.05.

val warmup : ?seconds:float -> unit -> unit

warmup ~seconds busy-loops the CPU to force it into full-power mode.

seconds is the warmup period. Default 1.

val core_counters : Probe.counter list

Wired-in counters that are always collected.