Dynamic randomly accessed memory (DRAM) is very slow. This can result in very different performance results during benchmarking.
There are two suggested strategies to this pitfall:
- Run multiple benchmarks with varying problem sets. Keep track of your memory footprint during tests.
- Use the @State annotation to dictate the JMH state. This annotation is sued to define the instance's scope. There are three states:
- Scope.Benchmark: The instance is shared across all threads that are running the same test.
- Scope.Group: One instance is allocated per thread group.
- Scope.Thread: Each thread will have its own instance. This is the default state.