v145 · Web APIs · Distribution Detector
Distribution detector
Run a workload, collect its performance.measure() samples, and detect whether they form one bell curve or two. Bimodal means cache hit/miss, cold/warm start, or fast/slow path — and median lies. Useful as a sanity check before you chart p95.
scenario
Histogram of 200 samples — bucket width auto.
Run a scenario to compute the distribution.
code
// Collect 200 samples
const samples = [];
for (let i = 0; i < 200; i++) {
performance.mark('s');
await workload();
performance.mark('e');
samples.push(performance.measure('m', 's', 'e').duration);
}
// Detect bimodality: dip test, or compare two-mode KMeans fit
// against a single-mode Gaussian fit. If two modes are far apart
// and both have meaningful mass, distribution is bimodal.
const { mode, gap, isBimodal } = analyse(samples);
if (isBimodal) {
console.warn('Bimodal — report p95 of both clusters, not the overall');
}