From aeada1fa7a7ab2d443cb1af7585a4ec506bad6bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 2 May 2021 18:26:09 +0200 Subject: [PATCH] Add standard deviation computation to time statistics MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/types/CommandStatistics.ts | 1 + src/utils/Statistics.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/types/CommandStatistics.ts b/src/types/CommandStatistics.ts index 84f2bdca..e4804f8a 100644 --- a/src/types/CommandStatistics.ts +++ b/src/types/CommandStatistics.ts @@ -20,6 +20,7 @@ export interface CommandStatisticsData { totalTimeMeasurement: number; avgTimeMeasurement: number; medTimeMeasurement: number; + stdDevTimeMeasurement: number; } export default interface CommandStatistics { diff --git a/src/utils/Statistics.ts b/src/utils/Statistics.ts index d194451a..65e3be5b 100644 --- a/src/utils/Statistics.ts +++ b/src/utils/Statistics.ts @@ -96,6 +96,20 @@ export default class Statistics { return (sortedDataSet[(middleIndex - 1)] + sortedDataSet[middleIndex]) / 2; } + private stdDeviation(dataSet: number[]): number { + let totalDataSet = 0; + for (const data of dataSet) { + totalDataSet += data; + } + const dataSetMean = totalDataSet / dataSet.length; + let totalGeometricDeviation = 0; + for (const data of dataSet) { + const deviation = data - dataSetMean; + totalGeometricDeviation += deviation * deviation; + } + return Math.sqrt(totalGeometricDeviation / dataSet.length); + } + private addPerformanceTimer(command: RequestCommand | IncomingRequestCommand, duration: number): void { // Map to proper command name const MAPCOMMAND = { @@ -119,6 +133,7 @@ export default class Statistics { this.commandsStatistics.commandsStatisticsData[command].avgTimeMeasurement = this.commandsStatistics.commandsStatisticsData[command].totalTimeMeasurement / this.commandsStatistics.commandsStatisticsData[command].countTimeMeasurement; Array.isArray(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries) ? this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries.push(duration) : this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries = [duration] as CircularArray; this.commandsStatistics.commandsStatisticsData[command].medTimeMeasurement = this.median(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries); + this.commandsStatistics.commandsStatisticsData[command].stdDevTimeMeasurement = this.stdDeviation(this.commandsStatistics.commandsStatisticsData[command].timeMeasurementSeries); } private logPrefix(): string { -- 2.34.1