Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.83 KB

jmh-benchmarks.adoc

File metadata and controls

45 lines (32 loc) · 1.83 KB

JMH benchmarks with Jenkins

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.

Writing benchmarks

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.

Running the benchmarks

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.

Sample benchmarks

Simplest Benchmark:

@JmhBenchmark
public class JmhStateBenchmark {
    public static class MyState extends JmhBenchmarkState {
    }

    @Benchmark
    public void benchmark(MyState state) {
        // benchmark code goes here
    }
}

Examples

Some benchmarks have been implemented in the Role Strategy Plugin which show setting up the benchmarks for many different situations.