Jmh

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Overview

Executes methods annotated with @Benchmark for a fixed time interval (by default a second) and measure the average execution time per execution.

Introduced by Java 8 & 9 in Action.

Example

https://github.com/NovaOrdis/playground/tree/master/java/jmh

The Maven shade plugin configuration available here: Maven Shade Plugin.

Annotations

@Benchmark

@Benchmark annotates the benchmark method.

JMH will produce the generated benchmark code for this method during compilation, register this method as the benchmark in the benchmark list, read out the default values from the annotations, and generally prepare the environment for the benchmark to run.

By default, jmh executes 20 warmup iterations and 20 measurement iterations per benchmark per fork. These values can be changed on command line or by configuring the annotation appropriately.

@Fork

@Fork(value=2, jvmArgs={"-Xms4G", "-Xmx4G"})

Specifies the number of executions in newly forked JVMs, to increase the reliability of the results, and JVM configuration to use.