Skip to content

Commit

Permalink
Introduced shared Benchmarks utility (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored Oct 16, 2024
1 parent 4840caf commit b8475f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +17,7 @@

import static java.util.stream.Collectors.toList;

public class Bench {
public class BatchedVsNonBatchedBenchmark {

@State(Scope.Benchmark)
public static class BenchmarkState {
Expand Down Expand Up @@ -74,14 +71,6 @@ public List<Integer> 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);
}
}
27 changes: 27 additions & 0 deletions src/test/java/com/pivovarit/collectors/benchmark/Benchmarks.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit b8475f4

Please sign in to comment.