Writing a Benchmark
@Benchmark and modes.
Writing a Benchmark
A JMH benchmark is just a method annotated with @Benchmark inside a regular class. JMH's annotation processor generates the harness around it. This lesson covers the annotations that define what and how you measure.
The @Benchmark Annotation
Mark any public method with @Benchmark and JMH will repeatedly invoke it, timing each call. The method's return value should be returned (not discarded) so JMH can consume it.
All lessons in this course
- Why JMH
- Writing a Benchmark
- Warmup and Iterations
- Avoiding Dead-Code Elimination