diff --git a/lib/internal/bench_runner/benchmark.js b/lib/internal/bench_runner/benchmark.js index 0ab3da9f24d8..cea0abc71e52 100644 --- a/lib/internal/bench_runner/benchmark.js +++ b/lib/internal/bench_runner/benchmark.js @@ -13,12 +13,14 @@ const { MathMin, MathRound, MathSqrt, + MathSumPrecise, Number, NumberIsFinite, NumberMAX_SAFE_INTEGER, ObjectFreeze, ObjectKeys, PromiseWithResolvers, + SafeArrayIterator, SafeSet, StringPrototypeToLowerCase, } = primordials; @@ -485,18 +487,6 @@ class BenchContext { } } -function arithmeticMean(values) { - let sum = 0; - let compensation = 0; - for (let i = 0; i < values.length; i++) { - const adjusted = values[i] - compensation; - const next = sum + adjusted; - compensation = (next - sum) - adjusted; - sum = next; - } - return sum / values.length; -} - function summarizeSamples(samples) { const rates = []; let min = Infinity; @@ -508,7 +498,7 @@ function summarizeSamples(samples) { max = MathMax(max, rate); } - const mean = arithmeticMean(rates); + const mean = MathSumPrecise(new SafeArrayIterator(rates)) / rates.length; let variance = 0; for (let i = 0; i < rates.length; i++) { const difference = rates[i] - mean;