From 6e0cdf8c310a873a9a688c41eedfaf75c2752077 Mon Sep 17 00:00:00 2001 From: Joakim Hassila Date: Thu, 14 Sep 2023 14:22:38 +0200 Subject: [PATCH] fix(patch): Show exact deviations if rounded are zero (#188) --- Sources/Benchmark/BenchmarkResult.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/Benchmark/BenchmarkResult.swift b/Sources/Benchmark/BenchmarkResult.swift index 7deb9831..6ac6279f 100644 --- a/Sources/Benchmark/BenchmarkResult.swift +++ b/Sources/Benchmark/BenchmarkResult.swift @@ -461,7 +461,10 @@ public struct BenchmarkResult: Codable, Comparable, Equatable { let absoluteDifference = (reverseComparison ? -1 : 1) * (lhs - threshold) if absoluteDifference != 0 { - let deviation = ThresholdDeviation(name: name, + let normalizedDifference = normalize(absoluteDifference) + let deviation: ThresholdDeviation + if normalizedDifference != 0 { + deviation = ThresholdDeviation(name: name, target: target, metric: metric, percentile: percentile, @@ -471,6 +474,18 @@ public struct BenchmarkResult: Codable, Comparable, Equatable { differenceThreshold: normalize(absoluteDifference), relative: false, units: scalingFactor) + } else { + deviation = ThresholdDeviation(name: name, + target: target, + metric: metric, + percentile: percentile, + baseValue: lhs, + comparisonValue: threshold, + difference: absoluteDifference, + differenceThreshold: absoluteDifference, + relative: false, + units: .count) + } if absoluteDifference < 0 { thresholdResults.improvements.append(deviation) } else {