What is JMH?
According to the Oxford English Dictionary, a benchmark is a standard or point of reference against which things may be compared or assessed. In programming, it is the way to compare the performance of applications, or just methods. The micro preface is focused on the latter—smaller code fragments rather than an application as a whole. JMH is a framework for measuring the performance of a single method.
That may appear to be very useful. Can we not just run a method 1,000 or 100,000 times in a loop, measure how long it took, and then calculate the average of the method’s performance? We can. The problem is that JVM is a much more complicated program than just a code-executing machine. It has optimization algorithms focused on making the application code run as fast as possible.
For example, let’s look at the following class:
class SomeClass {
public int...