Mouse
Mouse
I conducts a benchmark for List forEach. The benchmark code is as follows: ```java @State(Scope.Thread) @Warmup(iterations = 3) @Measurement(iterations = 10) @Fork(1) @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class IterationBenchmark { @Param({"10", "1000",...
My benchmark result is based on `# VM version: JDK 17.0.7, Java HotSpot(TM) 64-Bit Server VM, 17.0.7+8-LTS-224`.
Run your benchmark variant in `JDK 17.0.7`, the benchmark results are as follows: ``` Benchmark (n) Mode Cnt Score Error Units IterationBenchmark.forEach 100000 avgt 4 24642.541 ± 212.961 ns/op IterationBenchmark.forEachCacheArray...
I think the reason for this result is that the benchmark variant only consumes the array object itself, rather than consuming the data within the array object.
But my benchmark aligns with the function of forEach, obtaining and consuming one element at a time. We need to clarify what the JVM is doing.
My JMH version is `1.37`.
Upgrade JVM to `17.0.10` and get the same results as you: ``` # JMH version: 1.37 # VM version: JDK 17.0.10, Java HotSpot(TM) 64-Bit Server VM, 17.0.10+11-LTS-240 # VM invoker:...
Benchmark in JVM versions `17.0.8` and `17.0.9` respectively, the results indicate that the change occurred in `17.0.9`.
> for (int i = 0, max = size; ...) This code style has been applied to some of fastutil's templates, and if we don't use it, we'll need to...
Additionally, I have noticed that iterating over the array in the forward direction is faster and more readable compared to iterating in reverse order. I believe this could be considered...