Quant interview toolkit · experimental design

Six pairs of replay jobs and an exact test of a speedup

A team benchmarks a new pricing engine on six workloads. Each workload gets two isolated replay slots. A fair coin determines which slot runs the old engine and which runs the new one. The new engine finishes faster in five pairs. Before fitting a latency distribution, ask what results the six assignment coins alone could have produced.

Pair first, randomize within the pair

Record old-engine latency minus new-engine latency in milliseconds. Positive means the new engine was faster. The observed differences are

2,2,3,4,−1,2.2,\quad 2,\quad 3,\quad 4,\quad -1,\quad 2.

Their sum is 12 ms and the paired mean is 2 ms. Pairing removes the baseline difficulty of a workload from the comparison. Randomizing engine assignment within a pair prevents a systematic advantage from always running in the faster slot. Suppose slots are isolated so that running one engine cannot change another slot’s outcome.

Consider the sharp null that assigning either engine to any slot would give exactly the same latency for that slot. Under this hypothesis the two slot outcomes for each workload are fixed across assignments. Reversing its coin only changes the sign of the measured difference. Six independent fair coins give 26=642^6=64 equally likely assignments.

Count assignments with a sum this large

Choose the sum as the statistic and specify the direction in advance. For a one-sided test of improvement, count assignments with sum at least 12. If all signs are positive, the sum of the magnitudes is 14. Every magnitude assigned a negative sign subtracts twice its value. To stay at or above 12, the negative magnitudes can sum to at most 1.

Exactly two assignments qualify. One makes every difference positive. The other gives a minus sign only to the magnitude 1. The exact one-sided probability is 2/64=0.031252/64=0.03125. For a two-sided test using the absolute sum, the two mirror assignments also qualify, giving 4/64=0.06254/64=0.0625. Picking a direction after seeing the observations would give the one-sided number a misleading interpretation.

from itertools import product

differences = [2, 2, 3, 4, -1, 2]
observed = sum(differences)
totals = [
    sum(sign * abs(d) for sign, d in zip(signs, differences))
    for signs in product((-1, 1), repeat=len(differences))
]
print(sum(t >= observed for t in totals) / len(totals))
print(sum(abs(t) >= abs(observed) for t in totals) / len(totals))

Several assignments can give the same sum, especially here with three magnitudes equal to 2. Count assignments with multiplicity. Deduplicating the totals gives a distribution in which rare and common totals receive the same weight.

All 64 possible assignment sums
1-141-123-104-85-67-47-28072745648310112114Sum of paired latency differences (ms)2 of 64 assignments (3.125%)

What would a sign-only statistic say?

If only the direction of each speedup matters, use the number of positive differences. With no ties, each sign under the sharp null is an independent fair coin. Five or more positives occur in ((65)+(66))/64=7/64(\binom65+\binom66)/64=7/64 of assignments. That is a larger one-sided probability than the sum test gives. The sign-only statistic discards the fact that the sole adverse difference was the smallest in magnitude. Conversely, a single enormous difference can dominate the sum.

The paired mean estimates the average speedup across these workloads under the randomized design. The exact tail calculation tests the stronger hypothesis of zero effect on every slot. Effects of opposite signs can average to zero while violating that hypothesis. Generalizing to tomorrow’s workload mix also requires an argument about how these six workloads were selected.

Practice

ResolutionWith four independently randomized pairs, can the exact one-sided tail probability reach 0.05 or below?
Show answer

There are only 16 equally likely assignments. The observed assignment belongs to its own tail, so the smallest attainable tail probability is at least 1/16=0.06251/16=0.0625. More repetitions of the enumeration cannot improve resolution.

Design changeThe operator flipped a single coin to decide which engine ran first on all six workloads. Can you still enumerate 64 independent flips?
Show answer

There were only two possible global assignments. Reversing individual pairs creates experiments the operator could never have run. Reconstruct the reference distribution using the actual assignment mechanism. For future benchmarks, independent within-pair randomization gives finer resolution.