Fix benchmark script with 1 sample (#11320)

Previously the benchmark script would throw an error if asked to take
just 1 sample. Now it works, though the stats returned are of
dubious use.

The problem was that it was impossible to calculate the standard
deviation or margin of error of a set of 1. Instead it now returns
zero for both of those values in the single-sample case, which is what
it would return for two identical samples.
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent 3e959b6493
commit de55cd926a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      test/e2e/benchmark.js

@ -38,6 +38,9 @@ const minResult = calculateResult((array) => Math.min(...array));
const maxResult = calculateResult((array) => Math.max(...array)); const maxResult = calculateResult((array) => Math.max(...array));
const averageResult = calculateResult((array) => calculateAverage(array)); const averageResult = calculateResult((array) => calculateAverage(array));
const standardDeviationResult = calculateResult((array) => { const standardDeviationResult = calculateResult((array) => {
if (array.length === 1) {
return 0;
}
const average = calculateAverage(array); const average = calculateAverage(array);
const squareDiffs = array.map((value) => Math.pow(value - average, 2)); const squareDiffs = array.map((value) => Math.pow(value - average, 2));
return Math.sqrt(calculateAverage(squareDiffs)); return Math.sqrt(calculateAverage(squareDiffs));
@ -46,7 +49,7 @@ const standardDeviationResult = calculateResult((array) => {
const calculateMarginOfError = (array) => const calculateMarginOfError = (array) =>
ttest(array).confidence()[1] - calculateAverage(array); ttest(array).confidence()[1] - calculateAverage(array);
const marginOfErrorResult = calculateResult((array) => const marginOfErrorResult = calculateResult((array) =>
calculateMarginOfError(array), array.length === 1 ? 0 : calculateMarginOfError(array),
); );
async function profilePageLoad(pages, numSamples) { async function profilePageLoad(pages, numSamples) {

Loading…
Cancel
Save