OpenJDK:JMH Simple Usage
Introduction Few people have heard of JMH, yet if harnessed properly, can be a very valuable tool, typically when we come across performance considerations. Now and then we will come across a task that can be done multiple different ways but we are unsure which one is the best performing code. A quick JMH code over Java command line application can quickly tell you how is one code performing compared to the other. What JMH does when properly coded is to take your piece of code and run it for multiple warm up iterations to clear the memory cache, and then run it again over X amount iterations to obtain the averaged benchmark result. Elaboration Using JMH It is recommended to use JMH in the most simplest java way, ie using the old and standard public static void main: public static void main (String[] args) throws RunnerException { Options opt = new OptionsBuilder() .include(JmhTestRun. class .getSimpleName()) .forks( 1 ) .build() ; new Runner(opt).run