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 n0n_0 iterations (11 in Development, 55 in RegressionGate), it times a batch and retries while the batch is valid, shorter than the target batch time TT (5 ms in Development, 10 ms in RegressionGate), shorter than the maximum sample time (250 ms and 1 s), and below the iteration cap nmax⁡=10 000n_{\max} = 10\,000. The next size is

nk+1=min⁡(nmax⁡, max⁡(nk+1, ⌈nkT/tk⌉))(tk>0),nk+1=min⁡(nmax⁡, 10 nk)(tk≤0),n_{k+1} = \min\Bigl(n_{\max},\ \max\bigl(n_k + 1,\ \lceil n_k T / t_k \rceil\bigr)\Bigr) \quad (t_k > 0), \qquad n_{k+1} = \min(n_{\max},\ 10\, n_k) \quad (t_k \le 0),

where tkt_k is the measured batch time; the loop also stops when nk+1=nkn_{k+1} = n_k. Since nkT/tkn_k T / t_k is the size that would take exactly TT if the per-call time were constant, one retry usually suffices, and the nk+1n_k + 1 term guarantees progress when tkt_k is just below TT. Each implementation keeps its own nn (PerImplementation batch policy). An observation is then one timed batch of nn calls, recorded as the mean per-call time x=tbatch/nx = t_{\text{batch}} / n 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 mm blocks (m=10m = 10 for Development, 2020 for RegressionGate), after 33 or 55 exploratory blocks that the reductions ignore. In block jj every implementation is measured once: position r=0,…,K−1r = 0, \dots, K-1 runs implementation (r+j+o) mod K(r + j + o) \bmod K of the KK implementations, with the offset o=(s⊕seed) mod Ko = (s \oplus \mathit{seed}) \bmod K from the protocol’s order seed ss and the run seed. Over KK consecutive blocks each implementation therefore takes each position exactly once. For a baseline BB and a candidate CC the observations are sorted by block and paired:

dj=cj−bj,j=1,…,m.d_j = c_j - b_j, \qquad j = 1, \dots, m .

Slow drifts (frequency scaling, thermal state, background load) affect bjb_j and cjc_j of the same block similarly and cancel in djd_j.

Point estimates

With med⁡\operatorname{med} the sample median,

Δ%=100⋅med⁡(d)med⁡(b),speedup=med⁡(b)med⁡(b)+med⁡(d).\Delta_{\%} = 100 \cdot \frac{\operatorname{med}(d)}{\operatorname{med}(b)}, \qquad \text{speedup} = \frac{\operatorname{med}(b)}{\operatorname{med}(b) + \operatorname{med}(d)} .

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 Δ%\Delta_{\%} with a practical threshold δ\delta: Faster if Δ%≤−δ\Delta_{\%} \le -\delta, Slower if Δ%≥δ\Delta_{\%} \ge \delta, Equivalent otherwise. A difference smaller than δ\delta 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 s0≤⋯≤sN−1s_0 \le \dots \le s_{N-1} and f∈[0,1]f \in [0, 1], with h=f(N−1)h = f (N - 1),

Q(f)=s⌊h⌋+(h−⌊h⌋)(s⌈h⌉−s⌊h⌋),Q(f) = s_{\lfloor h \rfloor} + \bigl(h - \lfloor h \rfloor\bigr) \bigl(s_{\lceil h \rceil} - s_{\lfloor h \rfloor}\bigr),

so Q(1/2)Q(1/2) is the usual median (the mean of the two middle values for even NN).

The bootstrap confidence interval

The uncertainty of med⁡(d)\operatorname{med}(d) is estimated with the percentile bootstrap22 B. Efron, R. J. Tibshirani, An Introduction to the Bootstrap, Chapman & Hall, 1993, chapter 13. . For r=1,…,Rr = 1, \dots, R:

  1. draw mm indices i1,…,imi_1, \dots, i_m uniformly with replacement from {1,…,m}\{1, \dots, m\};
  2. compute the resampled median θr∗=med⁡(di1,…,dim)\theta^{*}_r = \operatorname{med}(d_{i_1}, \dots, d_{i_m}).

Sort θ(1)∗≤⋯≤θ(R)∗\theta^{*}_{(1)} \le \dots \le \theta^{*}_{(R)}. For a confidence level cc (in percent) let α=(100−c)/200\alpha = (100 - c) / 200. The interval is

[ L,U ]=[ Q∗(α), Q∗(1−α) ],\bigl[\, L, U \,\bigr] = \bigl[\, Q^{*}(\alpha),\ Q^{*}(1 - \alpha) \,\bigr],

with Q∗Q^{*} the type-7 quantile of the sorted bootstrap medians. With c=95c = 95 and R=10 000R = 10\,000 this is [Q∗(0.025),Q∗(0.975)][Q^{*}(0.025), Q^{*}(0.975)], i.e. linear interpolation at positions 249.975249.975 and 9749.0259749.025 of the sorted resamples (0-based). The interval is on med⁡(d)\operatorname{med}(d) 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 12,25,2712, 25, 27 and multiplies by 26858216577363387172685821657736338717, 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 00 is only reached from 00), so a nonzero seed never reaches the zero state; the period of the composite map is not the proven 264−12^{64} - 1 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 mm; if the states were uniform, each index would have probability within a factor 1±m/2641 \pm m / 2^{64} of 1/m1/m. 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

Δ%≥δandL>0:\Delta_{\%} \ge \delta \quad\text{and}\quad L > 0 :

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 tt 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 δ=3 %\delta = 3\,\%, R=10 000R = 10\,000 and c=95 %c = 95\,\%, so a regression gate cannot be weakened by a caller. paired_hotspot takes δ\delta and the seed from the caller and uses R=2000R = 2000 and c=95 %c = 95\,\% for exploratory hotspot reports.

Auto-tuning by median with an interquartile tie-break

tune_dataset scores each candidate by the median μc\mu_c of its valid confirmatory samples and, as secondary criterion, by their interquartile range IQRc\mathrm{IQR}_c (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 F={c:100 (μc−μmin⁡)/μmin⁡≤δ}F = \{c : 100\,(\mu_c - \mu_{\min})/\mu_{\min} \le \delta\} (those with μc=0\mu_c = 0 when μmin⁡=0\mu_{\min} = 0), which always contains every candidate with μc=μmin⁡\mu_c = \mu_{\min}, and returns the finalist with the smallest IQRc\mathrm{IQR}_c, ties broken by the smaller candidate id. Candidates that the practical threshold ties with the fastest are thus decided by stability, and δ=0\delta = 0 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 ℓ1,…,ℓS\ell_1, \dots, \ell_S (ordered by scale) into a crossover with @experiment.crossover_from_labels: it counts the indices ii with ℓi≠ℓi−1\ell_i \ne \ell_{i-1}. No change gives NoCrossover, exactly one change at ii gives Found with below == scale i−1i - 1 and at_or_above == scale ii, 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_regression and tune_dataset return 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. L≤UL \le U, because Q∗Q^{*} is monotone in its argument and α<1−α\alpha < 1 - \alpha for c>0c > 0.
  • Scale invariance. Multiplying all samples by a constant λ>0\lambda > 0 multiplies med⁡(d)\operatorname{med}(d), LL and UU by λ\lambda and leaves Δ%\Delta_{\%}, 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 BB and CC 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.py do 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

  1. R. J. Hyndman, Y. Fan, “Sample quantiles in statistical packages”, The American Statistician 50(4), 1996. ↩

  2. B. Efron, R. J. Tibshirani, An Introduction to the Bootstrap, Chapman & Hall, 1993, chapter 13. ↩

  3. S. Vigna, “An experimental exploration of Marsaglia’s xorshift generators, scrambled”, ACM TOMS 42(4), 2016. ↩