Skip to content
Ameen Abozaid
Planned lessonSRC-016-L08

Demo: a JMH benchmark that lied, and the fixed version

  • Lesson 8 of 8
  • Senior C
On This Lesson 3 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

expose benchmark traps and fix them; prepares SRC-016-LAB1.

Draft outline details

Step by step

  1. Show a benchmark claiming a new parser is 100 times faster.
  2. Inspect: the result is unused (dead-code elimination) and input is a constant.
  3. Planned mistake: run it once in a plain main method with a stopwatch. Fix: use JMH with forks, warm-up, and measurement iterations.
  4. Fix the benchmark: consume results through a Blackhole, use varied input from @State.
  5. Re-run: the true improvement is modest, with reported error bars.
  6. Add a note about what the microbenchmark does not show about the system.

Check your understanding

What suspicious sign did the first result show?

Show answer

An implausibly large speedup, which suggested the work was optimized away.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.