Skip to content

Commit faa106d

Browse files
committed
lib: replace Kahan summation with MathSumPrecise
Signed-off-by: LiviaMedeiros <livia@cirno.name>
1 parent 96de0e2 commit faa106d

1 file changed

Lines changed: 2 additions & 13 deletions

File tree

‎lib/internal/bench_runner/benchmark.js‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
MathMin,
1414
MathRound,
1515
MathSqrt,
16+
MathSumPrecise,
1617
Number,
1718
NumberIsFinite,
1819
NumberMAX_SAFE_INTEGER,
@@ -485,18 +486,6 @@ class BenchContext {
485486
}
486487
}
487488

488-
function arithmeticMean(values) {
489-
let sum = 0;
490-
let compensation = 0;
491-
for (let i = 0; i < values.length; i++) {
492-
const adjusted = values[i] - compensation;
493-
const next = sum + adjusted;
494-
compensation = (next - sum) - adjusted;
495-
sum = next;
496-
}
497-
return sum / values.length;
498-
}
499-
500489
function summarizeSamples(samples) {
501490
const rates = [];
502491
let min = Infinity;
@@ -508,7 +497,7 @@ function summarizeSamples(samples) {
508497
max = MathMax(max, rate);
509498
}
510499

511-
const mean = arithmeticMean(rates);
500+
const mean = MathSumPrecise(rates) / rates.length;
512501
let variance = 0;
513502
for (let i = 0; i < rates.length; i++) {
514503
const difference = rates[i] - mean;

0 commit comments

Comments
 (0)