Creating a benchmark project using JMH

Micro benchmarking itself is not an easy topic, and doing it correctly using languages like Java is a very difficult task. These difficulties arise from the way Java executes the code and the infrastructure required by JVM. Just as things like JIT and GC may affect the results of micro benchmarking heavily, to ensure that the result of each run is consistent and correct might not be an easy task to accomplish. To help with this problem, there are several frameworks that can help to ensure that the benchmark test runs properly. One of these frameworks is Java Microbenchmark Harness (JMH), which is a part of OpenJDK. This recipe will explain how developers can use this framework to benchmark his/her own code. ...

Get OpenJDK Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.