From faa106d293faf8612935a286dc06e189d1127bf2 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 3 Nov 2026 18:26:09 +0800 Subject: [PATCH 1/3] lib: replace Kahan summation with `MathSumPrecise` Signed-off-by: LiviaMedeiros --- lib/internal/bench_runner/benchmark.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/internal/bench_runner/benchmark.js b/lib/internal/bench_runner/benchmark.js index 0ab3da9f24d8..256672bfea26 100644 --- a/lib/internal/bench_runner/benchmark.js +++ b/lib/internal/bench_runner/benchmark.js @@ -13,6 +13,7 @@ const { MathMin, MathRound, MathSqrt, + MathSumPrecise, Number, NumberIsFinite, NumberMAX_SAFE_INTEGER, @@ -485,18 +486,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 +497,7 @@ function summarizeSamples(samples) { max = MathMax(max, rate); } - const mean = arithmeticMean(rates); + const mean = MathSumPrecise(rates) / rates.length; let variance = 0; for (let i = 0; i < rates.length; i++) { const difference = rates[i] - mean; From 78cc0f18f5061c7d75b373780e42b55157a739e0 Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Tue, 3 Nov 2026 23:51:23 +0800 Subject: [PATCH 2/3] Update lib/internal/bench_runner/benchmark.js Co-authored-by: Antoine du Hamel --- lib/internal/bench_runner/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/bench_runner/benchmark.js b/lib/internal/bench_runner/benchmark.js index 256672bfea26..3473275cc9cc 100644 --- a/lib/internal/bench_runner/benchmark.js +++ b/lib/internal/bench_runner/benchmark.js @@ -497,7 +497,7 @@ function summarizeSamples(samples) { max = MathMax(max, rate); } - const mean = MathSumPrecise(rates) / rates.length; + const mean = MathSumPrecise(new SafeArrayIterator(rates)) / rates.length; let variance = 0; for (let i = 0; i < rates.length; i++) { const difference = rates[i] - mean; From 525314bf5add3e46e0a3d46c52f7163d442836c2 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Tue, 3 Nov 2026 23:56:27 +0800 Subject: [PATCH 3/3] squash: import `SafeArrayIterator` Signed-off-by: LiviaMedeiros --- lib/internal/bench_runner/benchmark.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/bench_runner/benchmark.js b/lib/internal/bench_runner/benchmark.js index 3473275cc9cc..cea0abc71e52 100644 --- a/lib/internal/bench_runner/benchmark.js +++ b/lib/internal/bench_runner/benchmark.js @@ -20,6 +20,7 @@ const { ObjectFreeze, ObjectKeys, PromiseWithResolvers, + SafeArrayIterator, SafeSet, StringPrototypeToLowerCase, } = primordials;