RFR: 7903367: JMH: Add JMHSample_39_MemoryAccess [v2]
Vsevolod Tolstopyatov
duke at openjdk.org
Wed Oct 19 14:47:31 UTC 2022
On Mon, 17 Oct 2022 19:18:21 GMT, Michael Mirwaldt <duke at openjdk.org> wrote:
>> I propose this sample because overlooking the memory layout of e.g. ArrayLists can be a pitfall for benchmarks.
>> This new sample makes users of JMH aware of this problem. It teaches them how to use JMH right.
>> What do you think?
>
> Michael Mirwaldt has updated the pull request incrementally with one additional commit since the last revision:
>
> improved by proposals from first review
jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_39_MemoryAccess.java line 65:
> 63: * Benchmark Mode Cnt Score Error Units
> 64: * JMHSample_39_MemoryAccess.sumArray avgt 25 50.393 ± 0.407 ms/op
> 65: * JMHSample_39_MemoryAccess.sumArrayList avgt 25 299.868 ± 1.591 ms/op
It maybe can be even more educational if the benchmarks will expose how *unstable* such measurements are.
Having a third benchmark with the same `ArrayList` with the same `Integer` objects, but **shuffled** yields a completely different result. The educational hint here is that it can be GC who can do the actual shuffle
-------------
PR: https://git.openjdk.org/jmh/pull/85
More information about the jmh-dev
mailing list