Jmh: Difference between revisions
(6 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
=Overview= | =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. | Introduced by Java 8 & 9 in Action. | ||
Line 12: | Line 14: | ||
The Maven shade plugin configuration available here: [[Maven Shade Plugin#Example|Maven Shade Plugin]]. | The Maven shade plugin configuration available here: [[Maven Shade Plugin#Example|Maven Shade Plugin]]. | ||
=Annotations= | |||
==@Benchmark== | |||
<tt>@Benchmark</tt> 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. |
Latest revision as of 20:29, 6 April 2018
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
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.