Lyricdev
GitHub

struct Bench

pub struct Bench :: [OnFunction]

Conforms to OnFunction.

Marks a function as a benchmark, which lyric bench runs; also the measure it is handed.

A benchmark is fn name(&b: Bench), not private; they run one after another. b.iter { … } runs the block until the time of one run is known, b.bytes(n) says how many bytes a run handles; what was measured is in the bench's fields after the call.

Fields

pub var runs: int = 0

The runs of the round reported, the nanoseconds they took, and the allocations they made on this thread and their bytes.

pub var nanos: int = 0
pub var allocations: int = 0
pub var allocatedBytes: int = 0
pub var bytesPerRun: int = 0

The bytes a run handles, as bytes(n) said; 0 where it said nothing.

Methods

pub mut fn iter(body: fn() -> void): void

Runs body repeatedly until the time of one run is known.

Once to warm up, then rounds of ever more runs until one takes a tenth of a second, then five rounds of that many; the bench reports the round of the median time. The loop's call of body is in the time; blackBox keeps a result the compiler would otherwise drop.

pub mut fn bytes(n: int): void

Sets the bytes one run handles, so the report gives the bytes a second.

pub fn nanosPerRun(): float

Returns the nanoseconds one run took in the round reported; 0 before any run.