From 6a349d8417f160c06ede76a0f36c4dbe60a585bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 6 May 2023 19:55:36 +0200 Subject: [PATCH] fix: fix median and percentile calculation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/performance/PerformanceStatistics.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index a4dfd0b3..ecd6b3ab 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -191,7 +191,7 @@ export class PerformanceStatistics { const sortedDataSet = dataSet.slice().sort((a, b) => a - b); const middleIndex = Math.floor(sortedDataSet.length / 2); if (sortedDataSet.length % 2 === 0) { - return sortedDataSet[middleIndex / 2]; + return sortedDataSet[middleIndex]; } return (sortedDataSet[middleIndex - 1] + sortedDataSet[middleIndex]) / 2; } @@ -215,7 +215,7 @@ export class PerformanceStatistics { if (Number.isInteger(percentileIndex)) { return (sortedDataSet[percentileIndex] + sortedDataSet[percentileIndex + 1]) / 2; } - return sortedDataSet[Math.round(percentileIndex)]; + return sortedDataSet[Math.floor(percentileIndex)]; } private stdDeviation(dataSet: number[]): number { -- 2.34.1