Benchmarks v0.1.0
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.
Fields
| Name | Type | Description |
|---|---|---|
name | char8[..] | The benchmark's name, such as Parser::SmallDocument. |
run | func(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.
Fields
| Name | Type | Description |
|---|---|---|
iterations | uint64 | How many iterations the measured run made. |
elapsed | Duration | How 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
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.
Fields
| Name | Type | Description |
|---|---|---|
filter | char8[..] | Run only benchmarks whose names hold this text, or every benchmark when it is empty and filters is too. |
filters | char8[..][..] | More texts like filter: a benchmark runs when its name holds any of them, or filter. |
minimumTime | Duration | How long the measured run must last, at the least. |
maximumIterations | uint64 | The 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
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.
Type parameters
| Name | Description |
|---|---|
T | the value's type |
Parameters
| Name | Type | Description |
|---|---|---|
value | *T | the 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.
Parameters
| Name | Type | Description |
|---|---|---|
run | func(uint64) | the work, repeated as many times as it is told |
options | BenchmarkOptions | how 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.
Parameters
| Name | Type | Description |
|---|---|---|
benchmarks | BenchmarkCase[..] | the benchmarks |
options | BenchmarkOptions | which 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.
Parameters
| Name | Type | Description |
|---|---|---|
benchmarks | BenchmarkCase[..] | the benchmarks |
Returns: 0, or 2 for arguments it does not understand