diff --git a/scoredirector-benchmark.properties b/scoredirector-benchmark.properties index e190dc7..463df87 100644 --- a/scoredirector-benchmark.properties +++ b/scoredirector-benchmark.properties @@ -13,15 +13,15 @@ example=cloud_balancing # How many forks to run each example with. # Default is 10. -forks=1 +forks=2 # How many warmup iterations to run each example with. # Default is 5. -warmup_iterations=1 +warmup_iterations=2 # How many measurement iterations to run each example with. # Default is 5. -measurement_iterations=1 +measurement_iterations=2 # Ratio of benchmark score error to benchmark score above which warnings will be output. # The higher the threshold, the less reliable the benchmark score is. diff --git a/src/main/java/ai/timefold/solver/benchmarks/micro/common/ResultCapturingJMHRunner.java b/src/main/java/ai/timefold/solver/benchmarks/micro/common/ResultCapturingJMHRunner.java index 8a263e2..c86e5aa 100644 --- a/src/main/java/ai/timefold/solver/benchmarks/micro/common/ResultCapturingJMHRunner.java +++ b/src/main/java/ai/timefold/solver/benchmarks/micro/common/ResultCapturingJMHRunner.java @@ -57,6 +57,8 @@ private static final class ResultCapturingOutputFormat implements OutputFormat { private final Path resultsDirectory; private final OutputFormat delegate; + private int expectedIterationCount = -1; + private int iterationsRemaining = -1; public ResultCapturingOutputFormat(Path resultsDirectory, OutputFormat format) { this.resultsDirectory = resultsDirectory; @@ -71,26 +73,20 @@ public void iteration(BenchmarkParams benchParams, IterationParams params, int i @Override public void iterationResult(BenchmarkParams benchParams, IterationParams params, int iteration, IterationResult data) { delegate.iterationResult(benchParams, params, iteration, data); - } - - @Override - public void startBenchmark(BenchmarkParams benchParams) { - delegate.startBenchmark(benchParams); - } - - @Override - public void endBenchmark(BenchmarkResult result) { - delegate.endBenchmark(result); - var jfrFile = findJfrFile(resultsDirectory.toFile()); - if (jfrFile == null) { - return; - } - var unixTime = System.currentTimeMillis() / 1000; - var target = resultsDirectory.resolve(unixTime + "-" + jfrFile.getName()); - try { - Files.copy(jfrFile.toPath(), target); - } catch (IOException e) { - throw new IllegalStateException(e); + iterationsRemaining--; + if (iterationsRemaining == 0) { + iterationsRemaining = expectedIterationCount; + var jfrFile = findJfrFile(resultsDirectory.toFile()); + if (jfrFile == null) { + return; + } + var unixTime = System.currentTimeMillis() / 1000; + var target = resultsDirectory.resolve(unixTime + "-" + jfrFile.getName()); + try { + Files.copy(jfrFile.toPath(), target); + } catch (IOException e) { + throw new IllegalStateException(e); + } } } @@ -108,6 +104,18 @@ private static File findJfrFile(File file) { return null; } + @Override + public void startBenchmark(BenchmarkParams benchParams) { + expectedIterationCount = benchParams.getWarmup().getCount() + benchParams.getMeasurement().getCount(); + iterationsRemaining = expectedIterationCount; + delegate.startBenchmark(benchParams); + } + + @Override + public void endBenchmark(BenchmarkResult result) { + delegate.endBenchmark(result); + } + @Override public void startRun() { delegate.startRun();