- JMH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targeting the JVM.
- Developed by OpenJDK team
- Provides annotation driven API to easily develop correctly designed benchmarks
- Allows to modify behavior of compiler
Hello world example:
@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void testRecursiveFibonacci30(Blackhole blackhole){
blackhole.consume(recursiveFibonacci(30));
}
private static long recursiveFibonacci(int n) {
if (n <= 1) return n;
else return recursiveFibonacci(n-1) + recursiveFibonacci(n-2);
}
Pitfalls of Java benchmarks:
Alternatives:
Resources: