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 ( in Development,
in RegressionGate), it times a batch and retries while the batch is
valid, shorter than the target batch time (5 ms in Development, 10 ms in
RegressionGate), shorter than the maximum sample time (250 ms and 1 s), and
below the iteration cap . The next size is
where is the measured batch time; the loop also stops when
. Since is the size that would take exactly
if the per-call time were constant, one retry usually suffices, and the
term guarantees progress when is just below . Each
implementation keeps its own (PerImplementation batch policy). 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), after or exploratory blocks that the
reductions ignore. In block every implementation is measured once:
position runs implementation of the
implementations, with the offset
from the protocol’s order seed and the run seed. Over consecutive
blocks each implementation therefore takes each position exactly once. 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 xorshift-multiply generator modelled on xorshift64*33 S. Vigna, “An experimental exploration of Marsaglia’s xorshift generators, scrambled”, ACM TOMS 42(4), 2016. : each step applies the shifts and multiplies by , but, unlike xorshift64*, it keeps the multiplied value as the next state instead of only returning it. Each step is a bijection of the nonzero 64-bit words (the xorshift steps and the odd multiplier are invertible, and is only reached from ), so a nonzero seed never reaches the zero state; the period of the composite map is not the proven of xorshift64*, and nothing in the code establishes it. A zero seed is replaced by a fixed constant, and an index is the state modulo ; if the states were uniform, each index would have probability within a factor of . 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
and for exploratory hotspot reports.
Auto-tuning by median with an interquartile tie-break
tune_dataset scores each candidate by the median of its valid
confirmatory samples and, as secondary criterion, by their interquartile range
(the median of the upper half minus the median of the lower
half, the middle sample of an odd count belonging to neither; fewer than two
samples give 0). @tune.select_best keeps the finalists
(those with
when ), which always contains every candidate with
, and returns the finalist with the smallest
, ties broken by the smaller candidate id. Candidates that the
practical threshold ties with the fastest are thus decided by stability, and
keeps only the fastest medians. The result does not depend on the
order of candidate_ids.
An auto-tune run turns the per-dataset winners
(ordered by scale) into a crossover with
@experiment.crossover_from_labels: it counts the indices with
. No change gives NoCrossover, exactly one change at
gives Found with below scale and at_or_above scale
, and more than one gives NonMonotonic, for which a plain lookup table is printed instead of a piecewise policy. Because the winner of each
dataset is decided by the median and, within the practical threshold, by
the spread, noise between two nearly equal candidates can still produce several
changes.
Immutable fixtures with an oracle
immutable_bench generates each input once per scale and checks every
output against a reference. A faster implementation that computes the wrong
result fails the run instead of winning a comparison. The reference is only
as independent as the suite makes it: the arithmetic suites of binary
and decimal compare with the exact coefficient result, while the
elementary-function and decimal_gda suites use the core path itself as the
reference (so they check that the checked path agrees with the core) and the
interval suite uses the Binary kernel result.
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 and 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. Pairing is by position, not by block id, so if both implementations lose one invalid observation in different blocks the later pairs are formed across blocks. - 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. ↩