To start using JMH, the following dependencies have to be added to the pom.xml file:
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.21</version>
</dependency>
The name of the second .jar file, annprocess, provides a hint that JMH uses annotations. If you guessed so, you were correct. Here is an example of a benchmark created for testing the performance of an algorithm:
public class BenchmarkDemo {
public static void main(String... args) throws Exception{
org.openjdk.jmh.Main.main(args);
}
@Benchmark
public void testTheMethod() {
int res =...