-
-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathBenchmarkTest.java
More file actions
42 lines (38 loc) · 1.57 KB
/
BenchmarkTest.java
File metadata and controls
42 lines (38 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package jenkins.benchmark.jmh;
import org.junit.Test;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
/**
* Runs sample benchmarks from JUnit tests.
*/
public class BenchmarkTest {
@Test
public void testJmhBenchmarks() throws Exception {
// create directory for JMH reports
Path path = Paths.get("target/jmh-reports/");
Files.createDirectories(path);
// number of iterations is kept to a minimum just to verify that the benchmarks work without spending extra
// time during builds.
ChainedOptionsBuilder optionsBuilder =
new OptionsBuilder()
.forks(1)
.threads(1)
.warmupIterations(1)
.warmupBatchSize(1)
.measurementIterations(1)
.measurementBatchSize(1)
.shouldFailOnError(true)
.result("target/jmh-reports/jmh-benchmark-report.json")
.timeUnit(TimeUnit.MICROSECONDS)
.resultFormat(ResultFormatType.JSON);
BenchmarkFinder finder = new BenchmarkFinder(this.getClass().getPackage().getName());
finder.findBenchmarks(optionsBuilder);
new Runner(optionsBuilder.build()).run();
}
}