Skip to content

Commit

Permalink
Introduce isLongRunning to better manage longer benchmarks.
Browse files Browse the repository at this point in the history
The general reasoning here is, larger computations (like compilation) require more time to warm up.

We will start with spending 10s per iteration vs. 1s for regular benchmarks.

PiperOrigin-RevId: 725958018
  • Loading branch information
gkdn authored and copybara-github committed Feb 12, 2025
1 parent 0e3c8ed commit 9e0150a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ public void tearDown() {}
* Called one time after the benchmark is executed.
*/
public void tearDownOneTime() {}

/**
* Returns whether the benchmark is long running.
*
* <p>If the benchmark is long running, the framework uses a longer warmup and measurement time.
*/
public boolean isLongRunning() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ public final class BenchmarkExecutor {
}

public static BenchmarkResult execute(AbstractBenchmark benchmark) {
// Run the benchmark with 5 warm-up rounds of 1 second each and then with 5 measurement rounds
// of 1 second each.
return execute(benchmark, Clock.DEFAULT, 10, 5, 1000);
if (benchmark.isLongRunning()) {
// Run the benchmark with 5 warm-up / 5 measurement rounds 10 second each.
return execute(benchmark, Clock.DEFAULT, 10, 5, 10000);
} else {
// Run the benchmark with 5 warm-up / 5 measurement rounds 1 second each.
return execute(benchmark, Clock.DEFAULT, 10, 5, 1000);
}
}

public static void prepareForRunOnce(AbstractBenchmark benchmark) {
Expand Down Expand Up @@ -100,7 +104,11 @@ static BenchmarkResult execute(
benchmark.tearDownOneTime();

BenchmarkResult benchmarkResult = BenchmarkResult.from(throughputs);
log("Throughput: %s ops/ms", benchmarkResult.getAverageThroughput());
if (benchmark.isLongRunning()) {
log("Throughput: %s ops/s", benchmarkResult.getAverageThroughput() * 1000);
} else {
log("Throughput: %s ops/ms", benchmarkResult.getAverageThroughput());
}
return benchmarkResult;
}

Expand Down

0 comments on commit 9e0150a

Please sign in to comment.