vyrn

std/bench

9 exports, from std/bench.vyrn.

The runtime the vyrn bench transform links against. Only the synthesized bench main imports it, so its clock use never reaches a run or build.

Dependencies

The import graph shows the whole library.

Imported by
fn formatDuration(ns: Int64) -> String

A nanosecond duration in human units: ns below one microsecond, then microseconds, ms or s with two fractional digits.

type BenchResult = {
    name: String,
    minNs: Int64,
    medianNs: Int64,
    meanNs: Int64,
    samples: Int64,
    iters: Int64,
}

One bench's per-iteration statistics in nanoseconds, and the sample and iteration counts. Compare regressions on minNs, the least noisy.

fn benchMeasure(name: String, body: fn() -> Unit) -> BenchResult

Times one bench body and returns its statistics:

1. warm up for about 50 ms, discarding results;
2. double the per-sample iteration count until one sample takes 1 ms;
3. collect samples until at least 31 and 500 ms, capped at 2 s;
4. compute min, median and mean per-iteration time.

The body keeps its work alive with blackBox, so the compiler cannot delete it between iterations.

fn benchOne(name: String, width: Int64, body: fn() -> Unit)

Times one bench body and prints its report line. width is the label column width, computed from every bench name.

fn benchJson(results: Array<BenchResult>, backend: String, opt: String) -> String

The --json bench report: compact, benches in declaration order, every number an integer: { backend, opt, benches: [ { name, minNs, medianNs, meanNs, samples, iters } ] }.

Tests

5 test blocks in std/bench.vyrn. CI runs all of them.

Test names
  • formatDuration picks human units
  • median and mean over a small sample
  • padRight fills to width and never truncates
  • benchJson emits the locked schema in stable order
  • benchJson output round-trips through parseJson

Examples

    No example program imports this module.