From: Jérôme Benoit Date: Fri, 25 Aug 2023 10:37:22 +0000 (+0200) Subject: perf: optimize performance statistics computation X-Git-Tag: v1.2.21~67 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d4004f32353ed1ca6078154d6f4f450493c4ba51;p=e-mobility-charging-stations-simulator.git perf: optimize performance statistics computation Signed-off-by: Jérôme Benoit --- 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,