Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Perf] Include running average in per-second output #18742

Merged
merged 3 commits into from
Jan 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public class PerfStressProgram {
private static int[] completedOperations;
private static long[] lastCompletionNanoTimes;

private static int getCompletedOperations() {
return IntStream.of(completedOperations).sum();
}

private static double getOperationsPerSecond() {
return IntStream.range(0, completedOperations.length)
.mapToDouble(i -> completedOperations[i] / (((double) lastCompletionNanoTimes[i]) / 1000000000))
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
.sum();
}

/**
* Runs the performance tests passed to be executed.
*
Expand Down Expand Up @@ -177,11 +187,13 @@ public static void runTests(PerfStressTest<?>[] tests, boolean sync, int paralle

int[] lastCompleted = new int[] { 0 };
Disposable progressStatus = printStatus(
"=== " + title + " ===" + System.lineSeparator() + "Current\t\tTotal", () -> {
int totalCompleted = IntStream.of(completedOperations).sum();
"=== " + title + " ===" + System.lineSeparator() + "Current\t\tTotal\t\tAverage", () -> {
int totalCompleted = getCompletedOperations();
int currentCompleted = totalCompleted - lastCompleted[0];
double averageCompleted = getOperationsPerSecond();

lastCompleted[0] = totalCompleted;
return currentCompleted + "\t\t" + totalCompleted;
return String.format("%d\t\t%d\t\t%.0f", currentCompleted, totalCompleted, averageCompleted);
}, true, true);

if (sync) {
Expand All @@ -206,14 +218,12 @@ public static void runTests(PerfStressTest<?>[] tests, boolean sync, int paralle

System.out.println("=== Results ===");

int totalOperations = IntStream.of(completedOperations).sum();
double operationsPerSecond = IntStream.range(0, parallel)
.mapToDouble(i -> completedOperations[i] / (((double) lastCompletionNanoTimes[i]) / 1000000000))
.sum();
int totalOperations = getCompletedOperations();
double operationsPerSecond = getOperationsPerSecond();
double secondsPerOperation = 1 / operationsPerSecond;
double weightedAverageSeconds = totalOperations / operationsPerSecond;

System.out.printf("Completed %d operations in a weighted-average of %.2fs (%.2f ops/s, %.3f s/op)%n",
System.out.printf("Completed %,d operations in a weighted-average of %,.2fs (%,.2f ops/s, %,.3f s/op)%n",
totalOperations, weightedAverageSeconds, operationsPerSecond, secondsPerOperation);
System.out.println();
}
Expand Down