4. Java Microbenchmarking Harness (JMH) Framework by Vadym Kazulkin, ip.labs GmbH
Purpose of benchmarking
• Compare different implementations of code the same logic and choose the most
performant one.
• Identify bottlenecks in a suspected area of code
5. Java Microbenchmarking Harness (JMH) Framework by Vadym Kazulkin, ip.labs GmbH
Performance Measurement
this.initializeAndFillMyCollection();
final long start=System.nanoTime();
Collections.sort(myCollection);
final long end=System.nanoTime();
System.out.prinltn(“ “ +end-start);
First naive attempt
6. Java Microbenchmarking Harness (JMH) Framework by Vadym Kazulkin, ip.labs GmbH
Performance Measurement
public void measure(final int iterations)
{
for(int i=0; i<iterations; i++)
{
this.initializeAndFillMyCollection();
final long start=System.nanoTime();
Collections.sort(myCollection);
final long end=System.nanoTime();
}
System.out.prinltn(“average time “ +(end-start)/iterations);
}
Second naive attempt