jmh-basics: JMH tutorial module (dead-code elimination, Blackhole, constant folding, warmup/forks, state scopes, -prof gc)

Eight benchmark/demo classes, a deterministic test suite, and 12 captured output files
generated by scripts/run-all.sh on JDK 25.0.5 (Temurin) with JMH 1.37.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6Fj2JNt7dRev4pZPe
This commit is contained in:
2026-11-08 18:31:11 +00:00
co-authored by Claude Sonnet 5.5
parent f6237d4117
commit db129fb1ce
27 changed files with 2018 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
# JMH version: 1.37
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
# VM invoker: /tmp/tools/jdk-25.0.5+8/bin/java
# Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
# Warmup: 3 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 2 threads, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: com.ankurm.jmhbasics.StateScopeBenchmark.perThreadCounter
# Run progress: 0.00% complete, ETA 00:00:32
# Fork: 1 of 2
# Warmup Iteration 1: 7.678 ns/op
# Warmup Iteration 2: 8.112 ns/op
# Warmup Iteration 3: 7.597 ns/op
Iteration 1: 7.543 ns/op
Iteration 2: 7.587 ns/op
Iteration 3: 7.824 ns/op
Iteration 4: 8.115 ns/op
Iteration 5: 8.116 ns/op
# Run progress: 25.00% complete, ETA 00:00:24
# Fork: 2 of 2
# Warmup Iteration 1: 7.846 ns/op
# Warmup Iteration 2: 7.687 ns/op
# Warmup Iteration 3: 8.156 ns/op
Iteration 1: 7.978 ns/op
Iteration 2: 8.031 ns/op
Iteration 3: 7.915 ns/op
Iteration 4: 8.456 ns/op
Iteration 5: 7.931 ns/op
Result "com.ankurm.jmhbasics.StateScopeBenchmark.perThreadCounter":
7.950 ±(99.9%) 0.401 ns/op [Average]
(min, avg, max) = (7.543, 7.950, 8.456), stdev = 0.265
CI (99.9%): [7.549, 8.351] (assumes normal distribution)
# JMH version: 1.37
# VM version: JDK 25.0.5, OpenJDK 64-Bit Server VM, 25.0.5+8-LTS
# VM invoker: /tmp/tools/jdk-25.0.5+8/bin/java
# Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
# Warmup: 3 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Timeout: 10 min per iteration
# Threads: 2 threads, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: com.ankurm.jmhbasics.StateScopeBenchmark.sharedCounter
# Run progress: 50.00% complete, ETA 00:00:16
# Fork: 1 of 2
# Warmup Iteration 1: 28.549 ns/op
# Warmup Iteration 2: 35.212 ns/op
# Warmup Iteration 3: 35.105 ns/op
Iteration 1: 32.801 ns/op
Iteration 2: 35.661 ns/op
Iteration 3: 33.767 ns/op
Iteration 4: 32.006 ns/op
Iteration 5: 35.276 ns/op
# Run progress: 75.00% complete, ETA 00:00:08
# Fork: 2 of 2
# Warmup Iteration 1: 33.768 ns/op
# Warmup Iteration 2: 35.397 ns/op
# Warmup Iteration 3: 37.498 ns/op
Iteration 1: 34.394 ns/op
Iteration 2: 33.455 ns/op
Iteration 3: 28.463 ns/op
Iteration 4: 15.008 ns/op
Iteration 5: 35.151 ns/op
Result "com.ankurm.jmhbasics.StateScopeBenchmark.sharedCounter":
31.598 ±(99.9%) 9.365 ns/op [Average]
(min, avg, max) = (15.008, 31.598, 35.661), stdev = 6.194
CI (99.9%): [22.233, 40.963] (assumes normal distribution)
# Run complete. Total time: 00:00:33
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
NOTE: Current JVM experimentally supports Compiler Blackholes, and they are in use. Please exercise
extra caution when trusting the results, look into the generated code to check the benchmark still
works, and factor in a small probability of new VM bugs. Additionally, while comparisons between
different JVMs are already problematic, the performance difference caused by different Blackhole
modes can be very significant. Please make sure you use the consistent Blackhole mode for comparisons.
Benchmark Mode Cnt Score Error Units
StateScopeBenchmark.perThreadCounter avgt 10 7.950 ± 0.401 ns/op
StateScopeBenchmark.sharedCounter avgt 10 31.598 ± 9.365 ns/op