diff --git a/src/test/java/com/pivovarit/collectors/benchmark/Bench.java b/src/test/java/com/pivovarit/collectors/benchmark/BatchedVsNonBatchedBenchmark.java similarity index 82% rename from src/test/java/com/pivovarit/collectors/benchmark/Bench.java rename to src/test/java/com/pivovarit/collectors/benchmark/BatchedVsNonBatchedBenchmark.java index 4caa219e..6b4a1453 100644 --- a/src/test/java/com/pivovarit/collectors/benchmark/Bench.java +++ b/src/test/java/com/pivovarit/collectors/benchmark/BatchedVsNonBatchedBenchmark.java @@ -8,10 +8,7 @@ import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; -import org.openjdk.jmh.results.format.ResultFormatType; -import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; -import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.List; import java.util.concurrent.ExecutorService; @@ -20,7 +17,7 @@ import static java.util.stream.Collectors.toList; -public class Bench { +public class BatchedVsNonBatchedBenchmark { @State(Scope.Benchmark) public static class BenchmarkState { @@ -74,14 +71,6 @@ public List parallel_batch_streaming_collect(BenchmarkState state) { } public static void main(String[] args) throws RunnerException { - new Runner( - new OptionsBuilder() - .include(Bench.class.getSimpleName()) - .warmupIterations(5) - .measurementIterations(5) - .resultFormat(ResultFormatType.JSON) - .result("result.json") - .forks(1) - .build()).run(); + Benchmarks.run(BatchedVsNonBatchedBenchmark.class); } } diff --git a/src/test/java/com/pivovarit/collectors/benchmark/Benchmarks.java b/src/test/java/com/pivovarit/collectors/benchmark/Benchmarks.java new file mode 100644 index 00000000..1c2ecbe3 --- /dev/null +++ b/src/test/java/com/pivovarit/collectors/benchmark/Benchmarks.java @@ -0,0 +1,27 @@ +package com.pivovarit.collectors.benchmark; + +import org.openjdk.jmh.results.format.ResultFormatType; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.nio.file.Path; + +final class Benchmarks { + + private Benchmarks() { + } + + private static final Path BENCHMARKS_PATH = Path.of("src/test/resources/benchmarks/"); + + static void run(Class clazz) throws RunnerException { + new Runner(new OptionsBuilder() + .include(clazz.getSimpleName()) + .warmupIterations(3) + .measurementIterations(5) + .resultFormat(ResultFormatType.JSON) + .result(Benchmarks.BENCHMARKS_PATH.resolve("%s.json".formatted(clazz.getSimpleName())).toString()) + .forks(1) + .build()).run(); + } +} diff --git a/src/test/java/com/pivovarit/collectors/benchmark/result.json b/src/test/resources/benchmarks/BatchedVsNonBatchedBenchmark.json similarity index 100% rename from src/test/java/com/pivovarit/collectors/benchmark/result.json rename to src/test/resources/benchmarks/BatchedVsNonBatchedBenchmark.json