Benchmarks v0.1.0

Source
Measuring how long code takes per iteration, and keeping its results alive.

BenchmarkCase

pub struct BenchmarkCase {
    pub name: char8[..];
    pub run: func(uint64);
}

A benchmark: its name, which the runner reports and filters on, and the function that repeats the measured work as many times as it is told. Copy.

Source

Fields

NameTypeDescription
namechar8[..]The benchmark's name, such as Parser::SmallDocument.
runfunc(uint64)Runs the measured work the given number of times.

BenchmarkResult

pub struct BenchmarkResult {
    pub iterations: uint64;
    pub elapsed: Duration;
}

What a measurement found: how many iterations its final run made and how long that run took. Copy.

Source

Fields

NameTypeDescription
iterationsuint64How many iterations the measured run made.
elapsedDurationHow long the measured run took.

Methods

NanosecondsPerIteration

pub func NanosecondsPerIteration(self: &BenchmarkResult) -> float64

The average time one iteration took, in nanoseconds.

Returns: the time per iteration, or zero for a run of no iterations

Source

BenchmarkOptions

pub struct BenchmarkOptions {
    pub filter: char8[..];
    pub filters: char8[..][..];
    pub minimumTime: Duration;
    pub maximumIterations: uint64;
}

Which benchmarks a run chooses and how long each is measured. Copy.

Source

Fields

NameTypeDescription
filterchar8[..]Run only benchmarks whose names hold this text, or every benchmark when it is empty and filters is too.
filterschar8[..][..]More texts like filter: a benchmark runs when its name holds any of them, or filter.
minimumTimeDurationHow long the measured run must last, at the least.
maximumIterationsuint64The most iterations one run makes, which ends the growth for work too fast to reach minimumTime.

Constructors

BenchmarkOptions

pub func BenchmarkOptions() -> BenchmarkOptions

Options that measure every benchmark for at least 200 milliseconds and at most a billion iterations.

Returns: the options

Source

Consume<T>

pub func Consume<T>(value: *T)

Marks value as used, so the work that computed it is not removed as having no effect. It stores the value's address where the compiler cannot see it read, which costs one store.

Source

Type parameters

NameDescription
Tthe value's type

Parameters

NameTypeDescription
value*Tthe result to keep

Measure

pub func Measure(
    run: func(uint64),
    options: BenchmarkOptions
) -> BenchmarkResult

Runs run with a growing iteration count until one run lasts at least options.minimumTime or reaches options.maximumIterations, and reports that run. Each next count aims a little past the minimum from the rate measured so far, growing at least twofold and at most a hundredfold, so a measurement makes few runs whatever the work costs.

Source

Parameters

NameTypeDescription
runfunc(uint64)the work, repeated as many times as it is told
optionsBenchmarkOptionshow long to measure

Returns: the final run's iterations and time

RunBenchmarksWith

pub func RunBenchmarksWith(
    benchmarks: BenchmarkCase[..],
    options: BenchmarkOptions
) -> int

Measures the benchmarks that options choose, in order, and reports each as its time per iteration and the iterations it was measured over, then how many were measured.

Source

Parameters

NameTypeDescription
benchmarksBenchmarkCase[..]the benchmarks
optionsBenchmarkOptionswhich to run and how long to measure each

Returns: 0

RunBenchmarks

pub func RunBenchmarks(benchmarks: BenchmarkCase[..]) -> int

Measures the benchmarks the process's arguments choose. A plain argument is a filter, and a benchmark runs when its name holds any of them; --quick measures each for 10 milliseconds rather than 200, for checking that benchmarks still run.

Source

Parameters

NameTypeDescription
benchmarksBenchmarkCase[..]the benchmarks

Returns: 0, or 2 for arguments it does not understand