RFR: Samples/jmh sample 39 memory access
Aleksey Shipilev
shade at openjdk.org
Mon Oct 17 08:00:17 UTC 2022
On Wed, 12 Oct 2022 23:34:59 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?
Quick review...
jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_39_MemoryAccess.java line 64:
> 62: *
> 63: * Benchmark Mode Cnt Score Error Units
> 64: * JMHSample_39_MemoryAccess.sumArray avgt 25 5.117 ± 0.039 ns/op
5 ns to sum 1M elements seems way too low.
jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_39_MemoryAccess.java line 87:
> 85: long sum = 0;
> 86: for (int i = 0; i < N; i++) {
> 87: sum = intArray[i];
This needs to be `+=`.
jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_39_MemoryAccess.java line 96:
> 94: long sum = 0;
> 95: for (int i = 0; i < N; i++) {
> 96: sum = intList.get(i);
This needs to be `+=`.
-------------
PR: https://git.openjdk.org/jmh/pull/85
More information about the jmh-dev
mailing list