From 9eab310ff0a4cf89541a0e3de7839aed98661c02 Mon Sep 17 00:00:00 2001 From: Morten Haraldsen Date: Thu, 12 Sep 2024 10:46:07 +0200 Subject: [PATCH] Add guard for deviation -> Infinity --- .../ethlo/time/statistics/DurationPerformanceStatistics.java | 4 ++++ .../time/statistics/ThroughputPerformanceStatistics.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ethlo/time/statistics/DurationPerformanceStatistics.java b/src/main/java/com/ethlo/time/statistics/DurationPerformanceStatistics.java index 50201a2..88a3257 100644 --- a/src/main/java/com/ethlo/time/statistics/DurationPerformanceStatistics.java +++ b/src/main/java/com/ethlo/time/statistics/DurationPerformanceStatistics.java @@ -75,6 +75,10 @@ public Duration getStandardDeviation() { final IndexedCollection list = collectionStatistics.getList(); final int count = list.size(); + if (count == 0) + { + return Duration.ZERO; + } final double average = getAverage().toNanos(); BigDecimal sd = BigDecimal.valueOf(0); for (long l : list) diff --git a/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java b/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java index 452ad18..ff38239 100644 --- a/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java +++ b/src/main/java/com/ethlo/time/statistics/ThroughputPerformanceStatistics.java @@ -89,7 +89,7 @@ public Double getStandardDeviation() final int count = list.size(); if (count == 0) { - return null; + return 0D; } final double average = getAverage(); BigDecimal sd = BigDecimal.valueOf(0);