From d4004f32353ed1ca6078154d6f4f450493c4ba51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 25 Aug 2023 12:37:22 +0200 Subject: [PATCH] perf: optimize performance statistics computation 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 | 28 ++++++++---------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 281075c7..64216db2 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -217,7 +217,6 @@ export class PerformanceStatistics { this.statistics.statisticsData.set(entryName, {}); } // Update current statistics - this.statistics.updatedAt = new Date(); this.statistics.statisticsData.get(entryName)!.timeMeasurementCount = (this.statistics.statisticsData.get(entryName)?.timeMeasurementCount ?? 0) + 1; this.statistics.statisticsData.get(entryName)!.currentTimeMeasurement = entry.duration; @@ -240,29 +239,20 @@ export class PerformanceStatistics { timestamp: entry.startTime, value: entry.duration, })); - this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement = average( - extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!, - ), - ); - this.statistics.statisticsData.get(entryName)!.medTimeMeasurement = median( - extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!, - ), + const timeMeasurementValues = extractTimeSeriesValues( + this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!, ); + this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement = + average(timeMeasurementValues); + this.statistics.statisticsData.get(entryName)!.medTimeMeasurement = + median(timeMeasurementValues); this.statistics.statisticsData.get(entryName)!.ninetyFiveThPercentileTimeMeasurement = - nthPercentile( - extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!, - ), - 95, - ); + nthPercentile(timeMeasurementValues, 95); this.statistics.statisticsData.get(entryName)!.stdDevTimeMeasurement = stdDeviation( - extractTimeSeriesValues( - this.statistics.statisticsData.get(entryName)!.measurementTimeSeries!, - ), + timeMeasurementValues, this.statistics.statisticsData.get(entryName)!.avgTimeMeasurement, ); + this.statistics.updatedAt = new Date(); if ( Configuration.getConfigurationSection( ConfigurationSection.performanceStorage, -- 2.34.1