Book Image

OpenJDK Cookbook

Book Image

OpenJDK Cookbook

Overview of this book

Table of Contents (20 chapters)
OpenJDK Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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.

Getting ready

This recipe requires a machine with an Internet connection, Maven, Java SDK, and your favorite IDE that has support for Maven projects.

How to do it…

The following steps will take you through the process of creating a benchmark project...