bench design
Design goal
Performance claims in floating must be reproducible and must not be
confused with noise. bench turns the Maremark framework into a small,
repository-specific toolkit: benchmarks are immutable specifications with a
correctness oracle, every run records its environment and protocol, and
timings are reduced with robust, paired statistics whose uncertainty is
reported as a bootstrap confidence interval. Measurement (timing, streaming
JSONL) happens in the per-core test packages and tools/benchmark.py; this
package only describes experiments and reduces their data.
Mathematical background
What one observation measures
Maremark first calibrates a batch size for each implementation and dataset:
starting from the protocol’s minimum iterations, it times a batch and,
while the batch is shorter than the target batch time (5 ms in the
Development preset, 10 ms in RegressionGate) and the iteration cap is not
reached, retries with
where is the measured batch time. An observation is then one timed batch of calls, recorded as the mean per-call time in microseconds. Averaging inside a batch removes clock granularity; the batch-to-batch variation that remains is what the statistics below handle.
Blocks and pairing
The confirmatory phase consists of blocks ( for Development,
for RegressionGate). In block every implementation is measured
once, in the cyclic order of the implementations, with an
offset derived from the seed, so each implementation runs first equally
often over consecutive blocks. For a baseline and a candidate the
observations are sorted by block and paired:
Slow drifts (frequency scaling, thermal state, background load) affect and of the same block similarly and cancel in .
Point estimates
With the sample median,
The median has a breakdown point of 50 %: up to half of the blocks can be
arbitrarily disturbed (a preempted batch, a page-fault storm) without moving
the estimate arbitrarily. This is the outlier handling of the bench
reductions: no observation is discarded. Maremark’s protocols also name an
outlier policy (ReportOnly for Development, TukeyFence for
RegressionGate); it is part of the recorded protocol identity, but the
observations are emitted unfiltered and the reductions in this package do not
apply a filter.
The decision compares with a practical threshold :
Faster if , Slower if ,
Equivalent otherwise. A difference smaller than is treated as
irrelevant however precisely it is measured.
Sample quantiles
Maremark uses the linear-interpolation quantile (type 7 of Hyndman and Fan11 R. J. Hyndman, Y. Fan, “Sample quantiles in statistical packages”, The American Statistician 50(4), 1996. ): for sorted values and , with ,
so is the usual median (the mean of the two middle values for even ).
The bootstrap confidence interval
The uncertainty of is estimated with the percentile bootstrap22 B. Efron, R. J. Tibshirani, An Introduction to the Bootstrap, Chapman & Hall, 1993, chapter 13. . For :
- draw indices uniformly with replacement from ;
- compute the resampled median .
Sort . For a confidence level (in percent) let . The interval is
with the type-7 quantile of the sorted bootstrap medians. With and this is , i.e. linear interpolation at positions and of the sorted resamples (0-based). The interval is on in microseconds (not in percent).
The random indices come from a xorshift64* generator33 S. Vigna, “An experimental exploration of Marsaglia’s xorshift generators, scrambled”, ACM TOMS 42(4), 2016. seeded with the caller’s seed (a zero seed is replaced by a fixed constant), and an index is the state modulo ; the modulo bias is at most . With a fixed seed the interval is a deterministic function of the data, so reruns of an analysis reproduce it exactly.
The regression verdict
is_significant_regression requires both
the median slowdown must be practically relevant and the 95 % interval of the median paired difference must exclude zero on the slow side. The first condition guards against flagging tiny but precisely measured changes, the second against flagging large but noisy ones.
Design decisions
Paired medians instead of means
Timing distributions are right-skewed with occasional large outliers. The mean of differences and a interval would be dominated by those outliers; the median of block-paired differences is robust and needs no normality assumption, and the bootstrap gives its interval without a variance formula for the median.
Fixed parameters per use
confirmatory_regression fixes , and
, so a regression gate cannot be weakened by a caller.
paired_hotspot takes and the seed from the caller and uses
for exploratory hotspot reports. It passes the confidence as
0.95; Maremark interprets the value as a percentage, so the interval it
reports is the central 0.95 % of the bootstrap distribution, almost a point
at the bootstrap median. The suites only print from it, which is
unaffected.
Auto-tuning by minimum median
tune_dataset scores each candidate by the median of its valid confirmatory
samples and returns the one with the smallest median, breaking exact ties by
candidate id. The score is passed to @tune.select_best as both primary and
secondary criterion, so among the candidates within of the fastest
the smallest secondary, which is again the fastest, wins; the practical
threshold therefore has no effect on the choice. The crossover between two
candidates across scales is computed by Maremark from the per-dataset labels.
Immutable fixtures with an oracle
immutable_bench generates each input once per scale and checks every
output against an independent reference. A faster implementation that
computes the wrong result fails the run instead of winning a comparison.
Environment as data
environment records the target, profile and a data-type label with every
run, and marks what only the outer tool knows (machine, frequency policy,
commit) as external-metadata. A reader of two artifacts can then tell
whether their numbers are comparable; the package itself does not compare
runs across environments.
Correctness / invariants
- Determinism of the reduction. For fixed observations and seed,
paired_hotspot,confirmatory_regressionandtune_datasetreturn the same values on every run (sorting by block id, seeded generator, deterministic tie-breaking). - Pairing. Samples are paired by block order. Unequal sample counts are an
error (
MismatchedPairs), never a silent truncation. - Interval ordering. , because is monotone in its argument and for .
- Scale invariance. Multiplying all samples by a constant multiplies , and by and leaves , the decision and the verdict unchanged, so the unit of time does not matter.
Alternatives rejected
- Discarding outliers before averaging. Any fence needs a tuning constant and silently changes the sample; the median makes it unnecessary.
- Unpaired comparison of two sample sets. Drift between the measurement of and would enter the difference directly.
- Normal-theory intervals. They assume symmetric errors that timing data does not have.
Boundaries
- No timing, process control or file output: Maremark’s runner and
tools/benchmark.pydo that. - No absolute performance targets; thresholds apply to relative differences.
- Performance results never change correctness claims, and the benchmarks run only on the native target.
Footnotes
-
R. J. Hyndman, Y. Fan, “Sample quantiles in statistical packages”, The American Statistician 50(4), 1996. ↩
-
B. Efron, R. J. Tibshirani, An Introduction to the Bootstrap, Chapman & Hall, 1993, chapter 13. ↩
-
S. Vigna, “An experimental exploration of Marsaglia’s xorshift generators, scrambled”, ACM TOMS 42(4), 2016. ↩