3. WHAT IS JMH
Java Microbenchmark Harness
Building, running and analysing benchmarks written in
Java
Licensed under and
BSD for samples
Developed @
GPL 2, with the Classpath Exception
OpenJDK
4. WHY
Warm up
Dead code elimination
Loop unrolling
Branch prediction
False sharing
etc…
5. GET STARTED
It is as simple as generating project with maven archetype
mvn archetype:generate
DinteractiveMode=false
DarchetypeGroupId=org.openjdk.jmh
DarchetypeArtifactId=jmhjavabenchmarkarchetype
DgroupId=jpro.introjmh
DartifactId=getstarted
Dversion=1.0SNAPSHOT
Archetypes for kotlin, groovy, scala and java are
provided.
6. @BENCHMARK
JMH benchmarks code is placed in methods annotated with
@Benchmark
package jpro.introjmh;
import org.openjdk.jmh.annotations.Benchmark;
public class MyBenchmark {
@Benchmark
public void testMethod() {
// This is a demo/sample template for building your JMH benchmarks.
// Put your benchmark code here.
}
}
12. @BENCHMARKMODE
@BenchmarkMode(Mode.Throughput)
May be put at @Benchmarkmethod or at enclosing class
Available modes
Throughput- operations per time unit
AverageTime- average time per operation
SampleTime- sample time per operation
SingleShotTime- for single operation
any combination of the above
18. MISC
@OperationsPerInvocation - number of operations per
invocation
@CompilerControl - affect JIT compilation
@AuxCounters - state object int/long fields and methods
28. PERF/XPERF
perf - Linux perf Statistics
perfnorm - Linux perf statistics, normalized by operation
count
perfasm - Linux perf + PrintAssembly Profiler
xperf - Windows xperf + PrintAssembly Profiler
For PrintAssemby profiler you will need hsdis plugin
https://wiki.openjdk.java.net/display/HotSpot/PrintAssembly