Java Microbenchmark Harness allows running benchmarks
in the JVM. To run a benchmark where you need a Jenkins instance, you can use use JmhBenchmarkState
as a state in your benchmark. This creates a temporary Jenkins instance for each fork of the JMH benchmark.
A reference to the Jenkins instance is available through either the JmhBenchmarkState#getJenkins()
or through
Jenkins.getInstance()
like you would otherwise do. JmhBenchmarkState
provides setup()
and tearDown
methods
which can be overridden to configure the Jenkins instance according to your benchmark’s requirements.
The benchmarks can be run through JUnit tests. From a test method, you can use the OptionsBuilder
provided by JMH to
configure your benchmarks. For a sample, take a look at this.
Classes containing benchmarks are found automatically by the BenchmarkFinder
when annotated
with @JmhBenchmark
. Benchmark reports can also be generated and can be visualized using the jmh-report plugin.
Note
|
Benchmark methods need to be annotated by @Benchmark for JMH to detect them.
|
@JmhBenchmark
public class JmhStateBenchmark {
public static class MyState extends JmhBenchmarkState {
}
@Benchmark
public void benchmark(MyState state) {
// benchmark code goes here
}
}
Some benchmarks have been implemented in the Role Strategy Plugin which show setting up the benchmarks for many different situations.