From 9ef460b48277b9f57fe5ff6c9990f6eb8dbd9a9a Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Fri, 5 Feb 2021 21:48:35 -0800 Subject: [PATCH 1/3] Prevent divide-by-zero for incomplete threads --- common/Perf/Azure.Test.Perf/PerfProgram.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/Perf/Azure.Test.Perf/PerfProgram.cs b/common/Perf/Azure.Test.Perf/PerfProgram.cs index 902de3a3b69d..8fe1f1bc3b76 100644 --- a/common/Perf/Azure.Test.Perf/PerfProgram.cs +++ b/common/Perf/Azure.Test.Perf/PerfProgram.cs @@ -190,7 +190,10 @@ private static async Task RunTestsAsync(IPerfTest[] tests, PerfOptions options, var latency = warmup ? false : options.Latency; _completedOperations = new int[options.Parallel]; - _lastCompletionTimes = new TimeSpan[options.Parallel]; + + // Initialize _lastCompletionTimes with non-zero values to avoid divide-by-zero for threads + // with no completed operations. + _lastCompletionTimes = Enumerable.Repeat(TimeSpan.MinValue, options.Parallel).ToArray(); if (latency) { From 39c9893c97fd53807493cee642d9906ce4ce87a3 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Tue, 9 Feb 2021 11:14:04 -0800 Subject: [PATCH 2/3] Revert "Prevent divide-by-zero for incomplete threads" This reverts commit 9740d85d96a86414a0020338811f8d5f7049a7c5. --- common/Perf/Azure.Test.Perf/PerfProgram.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/common/Perf/Azure.Test.Perf/PerfProgram.cs b/common/Perf/Azure.Test.Perf/PerfProgram.cs index 8fe1f1bc3b76..902de3a3b69d 100644 --- a/common/Perf/Azure.Test.Perf/PerfProgram.cs +++ b/common/Perf/Azure.Test.Perf/PerfProgram.cs @@ -190,10 +190,7 @@ private static async Task RunTestsAsync(IPerfTest[] tests, PerfOptions options, var latency = warmup ? false : options.Latency; _completedOperations = new int[options.Parallel]; - - // Initialize _lastCompletionTimes with non-zero values to avoid divide-by-zero for threads - // with no completed operations. - _lastCompletionTimes = Enumerable.Repeat(TimeSpan.MinValue, options.Parallel).ToArray(); + _lastCompletionTimes = new TimeSpan[options.Parallel]; if (latency) { From 9bf08a08179a3f7d3cf5e7853301d50f3ee13231 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Tue, 9 Feb 2021 11:22:17 -0800 Subject: [PATCH 3/3] Prevent divide-by-zero for incomplete threads --- common/Perf/Azure.Test.Perf/PerfProgram.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/Perf/Azure.Test.Perf/PerfProgram.cs b/common/Perf/Azure.Test.Perf/PerfProgram.cs index 902de3a3b69d..8c1a904dc69d 100644 --- a/common/Perf/Azure.Test.Perf/PerfProgram.cs +++ b/common/Perf/Azure.Test.Perf/PerfProgram.cs @@ -25,7 +25,9 @@ public static class PerfProgram private static Channel<(TimeSpan, Stopwatch)> _pendingOperations; private static int CompletedOperations => _completedOperations.Sum(); - private static double OperationsPerSecond => _completedOperations.Zip(_lastCompletionTimes, (operations, time) => (operations / time.TotalSeconds)).Sum(); + private static double OperationsPerSecond => _completedOperations.Zip(_lastCompletionTimes, + (operations, time) => operations > 0 ? (operations / time.TotalSeconds) : 0) + .Sum(); public static async Task Main(Assembly assembly, string[] args) {