Demo: a JMH benchmark that lied, and the fixed version
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
- Show a benchmark claiming a new parser is 100 times faster.
- Inspect: the result is unused (dead-code elimination) and input is a constant.
- Planned mistake: run it once in a plain
mainmethod with a stopwatch. Fix: use JMH with forks, warm-up, and measurement iterations. - Fix the benchmark: consume results through a
Blackhole, use varied input from@State. - Re-run: the true improvement is modest, with reported error bars.
- 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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.