Besu includes JMH microbenchmarks for performance testing. This guide explains how to build and run them using Gradle.
- Java 21+ (ensure
JAVA_HOMEis set) - Gradle (you can use the wrapper:
./gradlew) - Optional: Async Profiler for low-overhead profiling
JMH tasks are defined in various modules such as ethereum:core, ethereum:eth, and ethereum:rlp.
./gradlew :ethereum:core:jmhThis runs all available benchmarks in the core module using default settings.
Gradle won't rerun a task by default with no changes, so to run subsequent times without changes add the gradle --rerun-tasks option.
./gradlew :ethereum:core:jmh --rerun-tasksTo run a specific benchmark class, use the -Pincludes and/or -Pexcludes project properties:
./gradlew :ethereum:core:jmh -Pincludes=SomeBenchmark -Pexcludes=TransientStorage,BlockHashThis uses a regex pattern so other kinds of regexes can be used.
For other configuration options run:
./gradlew help --task jmhTo profile benchmarks with Async Profiler:
./gradlew :ethereum:core:jmh \
-Pincludes=SomeBenchmark \
-PasyncProfiler=/path/to/libasyncProfiler.so \
-PasyncProfilerOptions="output=flamegraph"This will generate two html profiling files flame-cpu-forward.html and flame-cpu-reverse.html after the benchmark run.
Benchmark Mode Cnt Score Error Units
SomeBenchmark.benchmark avgt 20 3.893 ± 0.021 ns/op
SomeBenchmark.benchmark avgt 20 8.951 ± 0.149 ns/op