➜ java -Djmh.blackhole.mode=COMPILER -verbose:gc -jar target/benchmark.jar com.github.shautvast.benchmarks.loops.LoopBenchmark [0.003s][info][gc] Using G1 # JMH version: 1.36 # VM version: JDK 20.0.1, OpenJDK 64-Bit Server VM, 20.0.1+9-29 # VM invoker: /Users/Shautvast/Library/Java/JavaVirtualMachines/openjdk-20.0.1/Contents/Home/bin/java # VM options: -Djmh.blackhole.mode=COMPILER -verbose:gc # Blackhole mode: compiler (forced) # Warmup: 5 iterations, 10 s each # Measurement: 5 iterations, 10 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: com.github.shautvast.benchmarks.loops.LoopBenchmark.cStyle # Run progress: 0,00% complete, ETA 00:06:40 # Fork: 1 of 1 [0.003s][info][gc] Using G1 # Warmup Iteration 1: 1754,284 ns/op # Warmup Iteration 2: 1880,906 ns/op # Warmup Iteration 3: 1876,949 ns/op # Warmup Iteration 4: 1878,817 ns/op # Warmup Iteration 5: 1878,709 ns/op Iteration 1: 1878,447 ns/op Iteration 2: 1885,419 ns/op Iteration 3: 1875,054 ns/op Iteration 4: 1873,731 ns/op Iteration 5: 1874,494 ns/op Result "com.github.shautvast.benchmarks.loops.LoopBenchmark.cStyle": 1877,429 ±(99.9%) 18,547 ns/op [Average] (min, avg, max) = (1873,731, 1877,429, 1885,419), stdev = 4,817 CI (99.9%): [1858,882, 1895,976] (assumes normal distribution) # JMH version: 1.36 # VM version: JDK 20.0.1, OpenJDK 64-Bit Server VM, 20.0.1+9-29 # VM invoker: /Users/Shautvast/Library/Java/JavaVirtualMachines/openjdk-20.0.1/Contents/Home/bin/java # VM options: -Djmh.blackhole.mode=COMPILER -verbose:gc # Blackhole mode: compiler (forced) # Warmup: 5 iterations, 10 s each # Measurement: 5 iterations, 10 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: com.github.shautvast.benchmarks.loops.LoopBenchmark.enhancedForLoop # Run progress: 25,00% complete, ETA 00:05:00 # Fork: 1 of 1 [0.003s][info][gc] Using G1 # Warmup Iteration 1: 1756,742 ns/op # Warmup Iteration 2: 3557,042 ns/op # Warmup Iteration 3: 5425,266 ns/op # Warmup Iteration 4: 7101,989 ns/op # Warmup Iteration 5: 8871,875 ns/op Iteration 1: 10636,875 ns/op Iteration 2: 12417,359 ns/op Iteration 3: 14469,683 ns/op Iteration 4: 16248,110 ns/op Iteration 5: 17946,403 ns/op Result "com.github.shautvast.benchmarks.loops.LoopBenchmark.enhancedForLoop": 14343,686 ±(99.9%) 11238,581 ns/op [Average] (min, avg, max) = (10636,875, 14343,686, 17946,403), stdev = 2918,624 CI (99.9%): [3105,105, 25582,267] (assumes normal distribution) # JMH version: 1.36 # VM version: JDK 20.0.1, OpenJDK 64-Bit Server VM, 20.0.1+9-29 # VM invoker: /Users/Shautvast/Library/Java/JavaVirtualMachines/openjdk-20.0.1/Contents/Home/bin/java # VM options: -Djmh.blackhole.mode=COMPILER -verbose:gc # Blackhole mode: compiler (forced) # Warmup: 5 iterations, 10 s each # Measurement: 5 iterations, 10 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: com.github.shautvast.benchmarks.loops.LoopBenchmark.iterator # Run progress: 50,00% complete, ETA 00:03:20 # Fork: 1 of 1 [0.003s][info][gc] Using G1 # Warmup Iteration 1: 1761,563 ns/op # Warmup Iteration 2: 3563,533 ns/op # Warmup Iteration 3: 5422,159 ns/op # Warmup Iteration 4: 7090,576 ns/op # Warmup Iteration 5: 8872,802 ns/op Iteration 1: 10809,548 ns/op Iteration 2: 12595,235 ns/op Iteration 3: 14456,839 ns/op Iteration 4: 16226,710 ns/op Iteration 5: 18015,564 ns/op Result "com.github.shautvast.benchmarks.loops.LoopBenchmark.iterator": 14420,779 ±(99.9%) 10985,942 ns/op [Average] (min, avg, max) = (10809,548, 14420,779, 18015,564), stdev = 2853,014 CI (99.9%): [3434,837, 25406,721] (assumes normal distribution) # JMH version: 1.36 # VM version: JDK 20.0.1, OpenJDK 64-Bit Server VM, 20.0.1+9-29 # VM invoker: /Users/Shautvast/Library/Java/JavaVirtualMachines/openjdk-20.0.1/Contents/Home/bin/java # VM options: -Djmh.blackhole.mode=COMPILER -verbose:gc # Blackhole mode: compiler (forced) # Warmup: 5 iterations, 10 s each # Measurement: 5 iterations, 10 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Average time, time/op # Benchmark: com.github.shautvast.benchmarks.loops.LoopBenchmark.stream # Run progress: 75,00% complete, ETA 00:01:40 # Fork: 1 of 1 [0.003s][info][gc] Using G1 # Warmup Iteration 1: [0.262s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 27M->5M(520M) 1.402ms [0.403s][info][gc] GC(1) Pause Young (Normal) (G1 Evacuation Pause) 45M->5M(520M) 0.968ms [1.547s][info][gc] GC(2) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.898ms [2.638s][info][gc] GC(3) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.976ms [3.697s][info][gc] GC(4) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.873ms [4.757s][info][gc] GC(5) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.908ms [5.820s][info][gc] GC(6) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.862ms [6.886s][info][gc] GC(7) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.891ms [7.941s][info][gc] GC(8) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.886ms [9.006s][info][gc] GC(9) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.859ms [10.064s][info][gc] GC(10) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.891ms 690,839 ns/op # Warmup Iteration 2: [13.586s][info][gc] GC(11) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.895ms [16.410s][info][gc] GC(12) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.920ms [19.179s][info][gc] GC(13) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.953ms 2476,292 ns/op # Warmup Iteration 3: [23.479s][info][gc] GC(14) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 1.045ms [28.118s][info][gc] GC(15) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 1.149ms 3834,642 ns/op # Warmup Iteration 4: [33.560s][info][gc] GC(16) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.554ms [39.269s][info][gc] GC(17) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.602ms 4859,494 ns/op # Warmup Iteration 5: [46.829s][info][gc] GC(18) Pause Young (Normal) (G1 Evacuation Pause) 305M->5M(520M) 0.605ms 6219,711 ns/op Iteration 1: [55.043s][info][gc] GC(19) Pause Young (Normal) (G1 Evacuation Pause) 305M->6M(520M) 0.601ms 7151,609 ns/op Iteration 2: [64.223s][info][gc] GC(20) Pause Young (Normal) (G1 Evacuation Pause) 306M->6M(520M) 0.641ms 8273,040 ns/op Iteration 3: [74.942s][info][gc] GC(21) Pause Young (Normal) (G1 Evacuation Pause) 306M->6M(520M) 0.580ms 9447,701 ns/op Iteration 4: [87.347s][info][gc] GC(22) Pause Young (Normal) (G1 Evacuation Pause) 306M->6M(520M) 0.617ms 10760,223 ns/op Iteration 5: 12082,030 ns/op Result "com.github.shautvast.benchmarks.loops.LoopBenchmark.stream": 9542,921 ±(99.9%) 7523,289 ns/op [Average] (min, avg, max) = (7151,609, 9542,921, 12082,030), stdev = 1953,774 CI (99.9%): [2019,632, 17066,210] (assumes normal distribution) # Run complete. Total time: 00:06:40 REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial experiments, perform baseline and negative tests that provide experimental control, make sure the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts. Do not assume the numbers tell you what you want them to tell. NOTE: Current JVM experimentally supports Compiler Blackholes, and they are in use. Please exercise extra caution when trusting the results, look into the generated code to check the benchmark still works, and factor in a small probability of new VM bugs. Additionally, while comparisons between different JVMs are already problematic, the performance difference caused by different Blackhole modes can be very significant. Please make sure you use the consistent Blackhole mode for comparisons. Benchmark Mode Cnt Score Error Units LoopBenchmark.cStyle avgt 5 1877,429 ± 18,547 ns/op LoopBenchmark.enhancedForLoop avgt 5 14343,686 ± 11238,581 ns/op LoopBenchmark.iterator avgt 5 14420,779 ± 10985,942 ns/op LoopBenchmark.stream avgt 5 9542,921 ± 7523,289 ns/op MultiDim on  main [⇡] via ☕ v20.0.1 took 6m40s ➜