A robot team can benchmark the same motion programs before and after a software update. A long program may remain slower than a short one in both configurations, even when the update trims a similar amount of time from each. To estimate the mean change across the tested programs, keep each program's two measurements together when drawing bootstrap samples.

Choose the resampling unit

The natural unit in this example is the motion program. It contributes one before-and-after pair. SciPy's bootstrap function draws the same indices from both arrays when paired=True, so an observation selected on the before side brings along its own after measurement. Independent draws can combine the before value for a long motion with the after value for a short motion. That introduces variability unrelated to a program's measured change.

The following synthetic timings are in milliseconds. The baseline runs vary substantially, while the changes within program are small. A fixed random seed and a percentile interval make the example reproducible.

import numpy as np

from scipy.stats import bootstrap

before = np.array([10., 20., 30., 40., 50., 60.])

after = before + np.array([-1., -2., -1., -3., -2., -1.])

def mean_change(before, after, axis):

return np.mean(after - before, axis=axis)

result = bootstrap(

(before, after), mean_change, paired=True,

n_resamples=10_000, method="percentile",

rng=np.random.default_rng(42),

)

The observed mean change was approximately -1.67 ms. The paired 95% interval ran from about -2.33 to -1.17 ms. Running the same example with independent draws and the same initial seed produced roughly -20.50 to 18.17 ms. Those numbers describe this synthetic fixture. The width difference comes from preserving or discarding the alignment between program measurements.

Check the alignment before computing

Join the two configurations by a stable program or test case ID and check that each pair ran under comparable conditions. A missing entry should remain visible in the import report. Aligning two independently sorted tables by row position can silently change the pairs even when the array lengths match. If each program was repeated many times, decide beforehand whether the analysis targets a program-level summary or a repeated-measures design. Drawing every logged cycle independently can treat repeated runs of one program as extra independent programs.

The NIST handbook describes pairing as a natural correspondence between observations, including before-and-after measurements on the same objects. The SciPy reference documents how paired resampling preserves that correspondence when constructing the interval.

Sources

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.bootstrap.html

https://www.itl.nist.gov/div898/handbook/prc/section3/prc311.htm