refactor: cleanup performance statistics code
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Jul 2023 18:42:08 +0000 (20:42 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Jul 2023 18:42:08 +0000 (20:42 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/performance/PerformanceStatistics.ts

index a111eb450e66dcfb88e036977db48ee0dd351f21..80f53e54b80580c4ffa56b67c7b9a14b1b829b04 100644 (file)
@@ -204,26 +204,18 @@ export class PerformanceStatistics {
     // Update current statistics
     this.statistics.updatedAt = new Date();
     this.statistics.statisticsData.get(entryName).countTimeMeasurement =
-      this.statistics.statisticsData.get(entryName)?.countTimeMeasurement
-        ? this.statistics.statisticsData.get(entryName).countTimeMeasurement + 1
-        : 1;
+      (this.statistics.statisticsData.get(entryName)?.countTimeMeasurement ?? 0) + 1;
     this.statistics.statisticsData.get(entryName).currentTimeMeasurement = entry.duration;
-    this.statistics.statisticsData.get(entryName).minTimeMeasurement =
-      this.statistics.statisticsData.get(entryName)?.minTimeMeasurement
-        ? this.statistics.statisticsData.get(entryName).minTimeMeasurement > entry.duration
-          ? entry.duration
-          : this.statistics.statisticsData.get(entryName).minTimeMeasurement
-        : entry.duration;
-    this.statistics.statisticsData.get(entryName).maxTimeMeasurement =
-      this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement
-        ? this.statistics.statisticsData.get(entryName).maxTimeMeasurement < entry.duration
-          ? entry.duration
-          : this.statistics.statisticsData.get(entryName).maxTimeMeasurement
-        : entry.duration;
+    this.statistics.statisticsData.get(entryName).minTimeMeasurement = Math.min(
+      entry.duration,
+      this.statistics.statisticsData.get(entryName)?.minTimeMeasurement ?? Infinity
+    );
+    this.statistics.statisticsData.get(entryName).maxTimeMeasurement = Math.max(
+      entry.duration,
+      this.statistics.statisticsData.get(entryName)?.maxTimeMeasurement ?? -Infinity
+    );
     this.statistics.statisticsData.get(entryName).totalTimeMeasurement =
-      this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement
-        ? this.statistics.statisticsData.get(entryName).totalTimeMeasurement + entry.duration
-        : entry.duration;
+      (this.statistics.statisticsData.get(entryName)?.totalTimeMeasurement ?? 0) + entry.duration;
     this.statistics.statisticsData.get(entryName).avgTimeMeasurement =
       this.statistics.statisticsData.get(entryName).totalTimeMeasurement /
       this.statistics.statisticsData.get(entryName).countTimeMeasurement;