Microbenchmarking overview

Microbenchmarking is used to test the performance of a system. This differs from macrobenchmarking, which runs tests on different platforms for efficiency comparison and subsequent analysis. With microbenchmarking, we typically target a specific slice of code on one system such as a method or loop. The primary purpose of microbenchmarking is to identify optimization opportunities in our code.

There are multiple approaches to benchmarking; we will focus on using the JMH tool. So, why benchmark at all? Developers do not always concern themselves with performance issues unless performance is a stated requirement. This can lead to post-deployment surprises that could have been avoided if microbenchmarking was conducted as part of the development process.

Microbenchmarking takes place across several phases of a process. As shown in the following diagram, the process involves design, implementation, execution, analysis, and enhancement:

Microbenchmarking Process Phases

In the Design phase, we determine our goals and design our microbenchmark accordingly. In the Implement phase, we are writing the microbenchmark and then, in the Execution phase, we actually run the test. With microbenchmarking results in hand, we interpret and analyze the results in the Analysis phase. This leads to code improvements in the Enhancement phase. Once our code has been updated, we redesign the microbenchmarking test, adjust the implementation, or go straight to the Execution phase. This is a cyclical process that continues until we have achieved the performance optimization we identified in our goals.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset