Skip to content

Commit

Permalink
[Perf] Include running average in per-second output (#18071)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeharder authored Jan 20, 2021
1 parent 3f9a6ac commit d331a07
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions common/Perf/Azure.Test.Perf/PerfProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public static class PerfProgram
private static List<TimeSpan>[] _correctedLatencies;
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();

public static async Task Main(Assembly assembly, string[] args)
{
var testTypes = assembly.ExportedTypes
Expand Down Expand Up @@ -215,13 +218,15 @@ private static async Task RunTestsAsync(IPerfTest[] tests, PerfOptions options,
using var progressStatusCts = new CancellationTokenSource();
var progressStatusThread = PerfStressUtilities.PrintStatus(
$"=== {title} ===" + Environment.NewLine +
"Current\t\tTotal",
"Current\t\tTotal\t\tAverage",
() =>
{
var totalCompleted = _completedOperations.Sum();
var totalCompleted = CompletedOperations;
var currentCompleted = totalCompleted - lastCompleted;
var averageCompleted = OperationsPerSecond;
lastCompleted = totalCompleted;
return currentCompleted + "\t\t" + totalCompleted;
return $"{currentCompleted}\t\t{totalCompleted}\t\t{averageCompleted:F0}";
},
newLine: true,
progressStatusCts.Token,
Expand Down Expand Up @@ -273,12 +278,12 @@ private static async Task RunTestsAsync(IPerfTest[] tests, PerfOptions options,

Console.WriteLine("=== Results ===");

var totalOperations = _completedOperations.Sum();
var operationsPerSecond = _completedOperations.Zip(_lastCompletionTimes, (operations, time) => (operations / time.TotalSeconds)).Sum();
var totalOperations = CompletedOperations;
var operationsPerSecond = OperationsPerSecond;
var secondsPerOperation = 1 / operationsPerSecond;
var weightedAverageSeconds = totalOperations / operationsPerSecond;

Console.WriteLine($"Completed {totalOperations} operations in a weighted-average of {weightedAverageSeconds:N2}s " +
Console.WriteLine($"Completed {totalOperations:N0} operations in a weighted-average of {weightedAverageSeconds:N2}s " +
$"({operationsPerSecond:N2} ops/s, {secondsPerOperation:N3} s/op)");
Console.WriteLine();

Expand Down

0 comments on commit d331a07

Please sign in to comment.