Skip to content

Instantly share code, notes, and snippets.

@valery1707
Last active September 27, 2023 17:01
Show Gist options
  • Save valery1707/d9e5b7db6bcdbf1a273f7ab76732cf92 to your computer and use it in GitHub Desktop.
Save valery1707/d9e5b7db6bcdbf1a273f7ab76732cf92 to your computer and use it in GitHub Desktop.
Benchmark of different collection iteration modes
# Run complete. Total time: 00:32:54
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.
Benchmark (clazz) (size) Mode Cnt Score Error Units
CollectionIteration.forEachJava5 java.util.HashSet 1 avgt 5 18,992 ▒ 2,319 ns/op
CollectionIteration.forEachJava5 java.util.HashSet 10 avgt 5 73,098 ▒ 16,343 ns/op
CollectionIteration.forEachJava5 java.util.HashSet 100 avgt 5 711,547 ▒ 137,555 ns/op
CollectionIteration.forEachJava5 java.util.HashSet 1000 avgt 5 8740,817 ▒ 864,459 ns/op
CollectionIteration.forEachJava5 java.util.HashSet 10000 avgt 5 79751,656 ▒ 22466,079 ns/op
CollectionIteration.forEachJava5 java.util.HashSet 100000 avgt 5 902303,701 ▒ 21972,072 ns/op
CollectionIteration.forEachJava5 java.util.HashSet 1000000 avgt 5 10936961,027 ▒ 789268,610 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 1 avgt 5 8,712 ▒ 1,748 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 10 avgt 5 68,272 ▒ 9,293 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 100 avgt 5 670,425 ▒ 135,398 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 1000 avgt 5 8880,463 ▒ 3147,541 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 10000 avgt 5 102980,215 ▒ 6596,099 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 100000 avgt 5 2288516,706 ▒ 167288,805 ns/op
CollectionIteration.forEachJava5 java.util.TreeSet 1000000 avgt 5 25499101,317 ▒ 1880382,444 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 1 avgt 5 6,105 ▒ 0,294 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 10 avgt 5 52,190 ▒ 4,787 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 100 avgt 5 514,074 ▒ 70,125 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 1000 avgt 5 5139,090 ▒ 194,186 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 10000 avgt 5 52562,899 ▒ 2164,742 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 100000 avgt 5 487668,935 ▒ 23954,750 ns/op
CollectionIteration.forEachJava5 java.util.ArrayList 1000000 avgt 5 4900168,594 ▒ 693254,904 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 1 avgt 5 7,183 ▒ 0,100 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 10 avgt 5 59,612 ▒ 12,161 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 100 avgt 5 538,273 ▒ 49,122 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 1000 avgt 5 4962,808 ▒ 235,652 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 10000 avgt 5 56718,295 ▒ 2472,623 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 100000 avgt 5 593234,232 ▒ 58784,316 ns/op
CollectionIteration.forEachJava5 java.util.LinkedList 1000000 avgt 5 5854446,939 ▒ 286847,665 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 1 avgt 5 17,422 ▒ 1,689 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 10 avgt 5 61,255 ▒ 9,645 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 100 avgt 5 634,948 ▒ 54,910 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 1000 avgt 5 7487,745 ▒ 321,652 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 10000 avgt 5 70286,694 ▒ 13787,311 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 100000 avgt 5 664280,550 ▒ 53529,981 ns/op
CollectionIteration.forEachJava8 java.util.HashSet 1000000 avgt 5 9171906,393 ▒ 611099,613 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 1 avgt 5 8,062 ▒ 1,311 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 10 avgt 5 62,810 ▒ 7,814 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 100 avgt 5 618,589 ▒ 27,317 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 1000 avgt 5 7671,495 ▒ 475,425 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 10000 avgt 5 91506,802 ▒ 7341,722 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 100000 avgt 5 2006233,404 ▒ 116625,818 ns/op
CollectionIteration.forEachJava8 java.util.TreeSet 1000000 avgt 5 22684248,024 ▒ 967109,448 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 1 avgt 5 7,079 ▒ 1,427 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 10 avgt 5 52,414 ▒ 7,498 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 100 avgt 5 506,902 ▒ 78,066 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 1000 avgt 5 5081,673 ▒ 338,663 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 10000 avgt 5 54487,811 ▒ 4799,346 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 100000 avgt 5 443779,435 ▒ 32459,868 ns/op
CollectionIteration.forEachJava8 java.util.ArrayList 1000000 avgt 5 5489484,133 ▒ 335462,651 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 1 avgt 5 6,972 ▒ 1,393 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 10 avgt 5 58,331 ▒ 2,405 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 100 avgt 5 551,789 ▒ 90,763 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 1000 avgt 5 5006,108 ▒ 496,669 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 10000 avgt 5 56373,858 ▒ 8141,310 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 100000 avgt 5 543099,877 ▒ 64673,499 ns/op
CollectionIteration.forEachJava8 java.util.LinkedList 1000000 avgt 5 5979261,281 ▒ 810660,940 ns/op
CollectionIteration.forWithCache java.util.HashSet 1 avgt 5 3,916 ▒ 0,381 ns/op
CollectionIteration.forWithCache java.util.HashSet 10 avgt 5 28,559 ▒ 3,251 ns/op
CollectionIteration.forWithCache java.util.HashSet 100 avgt 5 283,599 ▒ 11,465 ns/op
CollectionIteration.forWithCache java.util.HashSet 1000 avgt 5 2721,797 ▒ 467,894 ns/op
CollectionIteration.forWithCache java.util.HashSet 10000 avgt 5 25923,739 ▒ 2376,663 ns/op
CollectionIteration.forWithCache java.util.HashSet 100000 avgt 5 231971,873 ▒ 16773,891 ns/op
CollectionIteration.forWithCache java.util.HashSet 1000000 avgt 5 2285100,343 ▒ 87161,457 ns/op
CollectionIteration.forWithCache java.util.TreeSet 1 avgt 5 4,353 ▒ 0,284 ns/op
CollectionIteration.forWithCache java.util.TreeSet 10 avgt 5 27,058 ▒ 0,954 ns/op
CollectionIteration.forWithCache java.util.TreeSet 100 avgt 5 285,838 ▒ 26,650 ns/op
CollectionIteration.forWithCache java.util.TreeSet 1000 avgt 5 2338,377 ▒ 271,221 ns/op
CollectionIteration.forWithCache java.util.TreeSet 10000 avgt 5 27094,426 ▒ 4437,769 ns/op
CollectionIteration.forWithCache java.util.TreeSet 100000 avgt 5 234173,054 ▒ 34240,842 ns/op
CollectionIteration.forWithCache java.util.TreeSet 1000000 avgt 5 2301509,952 ▒ 276471,816 ns/op
CollectionIteration.forWithCache java.util.ArrayList 1 avgt 5 3,928 ▒ 0,264 ns/op
CollectionIteration.forWithCache java.util.ArrayList 10 avgt 5 27,787 ▒ 1,932 ns/op
CollectionIteration.forWithCache java.util.ArrayList 100 avgt 5 277,649 ▒ 26,103 ns/op
CollectionIteration.forWithCache java.util.ArrayList 1000 avgt 5 2639,593 ▒ 284,712 ns/op
CollectionIteration.forWithCache java.util.ArrayList 10000 avgt 5 27075,820 ▒ 3259,092 ns/op
CollectionIteration.forWithCache java.util.ArrayList 100000 avgt 5 228632,059 ▒ 10722,460 ns/op
CollectionIteration.forWithCache java.util.ArrayList 1000000 avgt 5 2388151,533 ▒ 344968,432 ns/op
CollectionIteration.forWithCache java.util.LinkedList 1 avgt 5 3,968 ▒ 0,349 ns/op
CollectionIteration.forWithCache java.util.LinkedList 10 avgt 5 27,197 ▒ 3,145 ns/op
CollectionIteration.forWithCache java.util.LinkedList 100 avgt 5 286,004 ▒ 44,047 ns/op
CollectionIteration.forWithCache java.util.LinkedList 1000 avgt 5 2781,230 ▒ 763,843 ns/op
CollectionIteration.forWithCache java.util.LinkedList 10000 avgt 5 26440,367 ▒ 2627,838 ns/op
CollectionIteration.forWithCache java.util.LinkedList 100000 avgt 5 229499,472 ▒ 20563,846 ns/op
CollectionIteration.forWithCache java.util.LinkedList 1000000 avgt 5 2272003,494 ▒ 47359,552 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 1 avgt 5 4,658 ▒ 0,353 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 10 avgt 5 31,329 ▒ 11,191 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 100 avgt 5 325,907 ▒ 64,379 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 1000 avgt 5 2883,327 ▒ 372,932 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 10000 avgt 5 28517,627 ▒ 3022,866 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 100000 avgt 5 288016,170 ▒ 71795,317 ns/op
CollectionIteration.forWithoutCache java.util.HashSet 1000000 avgt 5 2755490,934 ▒ 95862,196 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 1 avgt 5 4,979 ▒ 0,428 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 10 avgt 5 34,419 ▒ 6,246 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 100 avgt 5 327,914 ▒ 55,797 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 1000 avgt 5 3399,117 ▒ 264,342 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 10000 avgt 5 36060,965 ▒ 12719,112 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 100000 avgt 5 312961,500 ▒ 11420,610 ns/op
CollectionIteration.forWithoutCache java.util.TreeSet 1000000 avgt 5 3212297,518 ▒ 472371,454 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 1 avgt 5 4,214 ▒ 0,490 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 10 avgt 5 29,218 ▒ 1,677 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 100 avgt 5 291,733 ▒ 10,328 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 1000 avgt 5 2850,669 ▒ 102,313 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 10000 avgt 5 27795,037 ▒ 2656,785 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 100000 avgt 5 287076,894 ▒ 61863,764 ns/op
CollectionIteration.forWithoutCache java.util.ArrayList 1000000 avgt 5 2835221,190 ▒ 226637,400 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 1 avgt 5 4,465 ▒ 1,663 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 10 avgt 5 29,645 ▒ 1,429 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 100 avgt 5 305,993 ▒ 117,803 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 1000 avgt 5 2890,434 ▒ 312,834 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 10000 avgt 5 29473,055 ▒ 9648,146 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 100000 avgt 5 290398,407 ▒ 44692,017 ns/op
CollectionIteration.forWithoutCache java.util.LinkedList 1000000 avgt 5 2824249,643 ▒ 196972,937 ns/op
CollectionIteration.iterator java.util.HashSet 1 avgt 5 16,601 ▒ 0,895 ns/op
CollectionIteration.iterator java.util.HashSet 10 avgt 5 59,864 ▒ 7,383 ns/op
CollectionIteration.iterator java.util.HashSet 100 avgt 5 592,730 ▒ 21,646 ns/op
CollectionIteration.iterator java.util.HashSet 1000 avgt 5 7302,729 ▒ 810,425 ns/op
CollectionIteration.iterator java.util.HashSet 10000 avgt 5 65271,237 ▒ 2318,993 ns/op
CollectionIteration.iterator java.util.HashSet 100000 avgt 5 876800,494 ▒ 32635,926 ns/op
CollectionIteration.iterator java.util.HashSet 1000000 avgt 5 9245969,127 ▒ 819826,377 ns/op
CollectionIteration.iterator java.util.TreeSet 1 avgt 5 7,711 ▒ 0,530 ns/op
CollectionIteration.iterator java.util.TreeSet 10 avgt 5 62,329 ▒ 9,703 ns/op
CollectionIteration.iterator java.util.TreeSet 100 avgt 5 627,934 ▒ 46,457 ns/op
CollectionIteration.iterator java.util.TreeSet 1000 avgt 5 7674,730 ▒ 311,090 ns/op
CollectionIteration.iterator java.util.TreeSet 10000 avgt 5 96070,822 ▒ 7756,983 ns/op
CollectionIteration.iterator java.util.TreeSet 100000 avgt 5 2182046,208 ▒ 114486,992 ns/op
CollectionIteration.iterator java.util.TreeSet 1000000 avgt 5 23091181,277 ▒ 2513262,802 ns/op
CollectionIteration.iterator java.util.ArrayList 1 avgt 5 5,970 ▒ 0,612 ns/op
CollectionIteration.iterator java.util.ArrayList 10 avgt 5 51,845 ▒ 2,417 ns/op
CollectionIteration.iterator java.util.ArrayList 100 avgt 5 506,821 ▒ 51,676 ns/op
CollectionIteration.iterator java.util.ArrayList 1000 avgt 5 5004,763 ▒ 332,131 ns/op
CollectionIteration.iterator java.util.ArrayList 10000 avgt 5 51679,896 ▒ 15084,112 ns/op
CollectionIteration.iterator java.util.ArrayList 100000 avgt 5 425053,231 ▒ 36586,680 ns/op
CollectionIteration.iterator java.util.ArrayList 1000000 avgt 5 4839277,820 ▒ 819227,053 ns/op
CollectionIteration.iterator java.util.LinkedList 1 avgt 5 6,629 ▒ 0,335 ns/op
CollectionIteration.iterator java.util.LinkedList 10 avgt 5 55,010 ▒ 14,404 ns/op
CollectionIteration.iterator java.util.LinkedList 100 avgt 5 539,771 ▒ 36,756 ns/op
CollectionIteration.iterator java.util.LinkedList 1000 avgt 5 5008,099 ▒ 397,445 ns/op
CollectionIteration.iterator java.util.LinkedList 10000 avgt 5 57080,290 ▒ 8650,466 ns/op
CollectionIteration.iterator java.util.LinkedList 100000 avgt 5 596263,610 ▒ 72067,562 ns/op
CollectionIteration.iterator java.util.LinkedList 1000000 avgt 5 6003177,428 ▒ 698900,674 ns/op
Collection Iteration 1 10 100 1000 10000 100000 1000000
java.util.HashSet forWithoutCache 14,517±1,909 5,756±0,205 5,200±0,123 4,345±0,044 4,914±0,100 4,300±3,529 3,106±0,266
java.util.HashSet forWithCache 13,170±0,136 5,418±0,128 4,423±0,028 4,330±0,070 4,626±0,394 4,633±0,121 2,155±0,085
java.util.HashSet forEachJava5 22,325±3,616 6,261±0,057 5,332±0,070 6,577±0,112 4,852±0,042 6,945±4,538 7,878±2,565
java.util.HashSet forEachJava8 22,187±4,054 5,994±0,085 6,099±0,874 7,198±0,104 6,067±0,127 7,395±3,304 8,082±2,750
java.util.HashSet iterator 21,545±0,506 5,867±0,289 6,250±0,042 6,769±0,052 5,021±0,083 6,915±4,615 7,994±3,090
java.util.TreeSet forWithoutCache 13,952±0,987 4,000±0,071 3,201±0,048 3,071±0,290 3,001±0,364 2,985±0,047 2,936±0,024
java.util.TreeSet forWithCache 15,543±0,988 5,278±0,069 4,475±0,171 3,679±0,066 4,582±0,070 4,649±0,150 2,143±0,017
java.util.TreeSet forEachJava5 14,747±1,429 6,015±0,109 5,515±0,039 7,119±0,094 8,483±0,191 18,861±6,052 22,251±0,675
java.util.TreeSet forEachJava8 14,758±2,569 6,523±0,189 5,567±0,062 7,132±0,122 8,329±0,430 20,552±1,754 21,190±0,501
java.util.TreeSet iterator 13,588±1,197 5,915±0,310 5,441±0,358 7,233±0,134 8,429±0,214 19,731±1,744 21,754±1,414
java.util.ArrayList forWithoutCache 14,598±1,207 5,819±0,181 4,545±0,126 5,220±1,876 4,598±0,078 4,229±3,076 2,610±0,015
java.util.ArrayList forWithCache 14,866±0,262 5,252±0,618 4,493±0,125 4,320±0,024 4,579±0,053 4,578±0,062 2,140±0,015
java.util.ArrayList forEachJava5 13,899±0,124 4,970±0,094 4,187±0,134 4,136±0,042 4,072±0,031 4,176±0,355 4,300±0,301
java.util.ArrayList forEachJava8 13,038±0,151 5,006±0,419 4,140±0,111 3,947±0,045 3,869±0,415 3,929±0,134 4,121±0,872
java.util.ArrayList iterator 12,198±0,143 4,595±0,115 4,096±0,587 4,001±0,021 3,936±0,026 3,933±0,005 3,943±0,040
java.util.LinkedList forWithoutCache 14,349±0,128 5,910±0,202 5,997±2,523 4,333±0,060 4,595±0,029 4,216±3,007 2,612±0,035
java.util.LinkedList forWithCache 12,962±0,058 5,114±0,062 4,908±0,096 4,311±0,018 4,585±0,046 4,576±0,070 2,144±0,002
java.util.LinkedList forEachJava5 14,650±1,838 5,212±0,033 5,059±1,531 3,973±0,403 4,349±0,065 4,900±0,054 5,022±0,484
java.util.LinkedList forEachJava8 13,454±0,335 5,151±0,044 4,701±0,229 4,044±0,060 4,313±0,054 5,164±0,642 5,094±0,777
java.util.LinkedList iterator 14,137±2,266 5,221±0,229 4,561±0,093 3,943±0,061 4,340±0,303 4,917±0,090 5,096±0,665
# Run complete. Total time: 01:57:37
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.
Benchmark (clazz) (mode) Mode Cnt Score Error Units
CollectionIteration.benchmark_1 java.util.HashSet forWithoutCache avgt 5 14,517 ± 1,909 ns/op
CollectionIteration.benchmark_1 java.util.HashSet forWithCache avgt 5 13,170 ± 0,136 ns/op
CollectionIteration.benchmark_1 java.util.HashSet forEachJava5 avgt 5 22,325 ± 3,616 ns/op
CollectionIteration.benchmark_1 java.util.HashSet forEachJava8 avgt 5 22,187 ± 4,054 ns/op
CollectionIteration.benchmark_1 java.util.HashSet iterator avgt 5 21,545 ± 0,506 ns/op
CollectionIteration.benchmark_1 java.util.TreeSet forWithoutCache avgt 5 13,952 ± 0,987 ns/op
CollectionIteration.benchmark_1 java.util.TreeSet forWithCache avgt 5 15,543 ± 0,988 ns/op
CollectionIteration.benchmark_1 java.util.TreeSet forEachJava5 avgt 5 14,747 ± 1,429 ns/op
CollectionIteration.benchmark_1 java.util.TreeSet forEachJava8 avgt 5 14,758 ± 2,569 ns/op
CollectionIteration.benchmark_1 java.util.TreeSet iterator avgt 5 13,588 ± 1,197 ns/op
CollectionIteration.benchmark_1 java.util.ArrayList forWithoutCache avgt 5 14,598 ± 1,207 ns/op
CollectionIteration.benchmark_1 java.util.ArrayList forWithCache avgt 5 14,866 ± 0,262 ns/op
CollectionIteration.benchmark_1 java.util.ArrayList forEachJava5 avgt 5 13,899 ± 0,124 ns/op
CollectionIteration.benchmark_1 java.util.ArrayList forEachJava8 avgt 5 13,038 ± 0,151 ns/op
CollectionIteration.benchmark_1 java.util.ArrayList iterator avgt 5 12,198 ± 0,143 ns/op
CollectionIteration.benchmark_1 java.util.LinkedList forWithoutCache avgt 5 14,349 ± 0,128 ns/op
CollectionIteration.benchmark_1 java.util.LinkedList forWithCache avgt 5 12,962 ± 0,058 ns/op
CollectionIteration.benchmark_1 java.util.LinkedList forEachJava5 avgt 5 14,650 ± 1,838 ns/op
CollectionIteration.benchmark_1 java.util.LinkedList forEachJava8 avgt 5 13,454 ± 0,335 ns/op
CollectionIteration.benchmark_1 java.util.LinkedList iterator avgt 5 14,137 ± 2,266 ns/op
CollectionIteration.benchmark_10 java.util.HashSet forWithoutCache avgt 5 5,756 ± 0,205 ns/op
CollectionIteration.benchmark_10 java.util.HashSet forWithCache avgt 5 5,418 ± 0,128 ns/op
CollectionIteration.benchmark_10 java.util.HashSet forEachJava5 avgt 5 6,261 ± 0,057 ns/op
CollectionIteration.benchmark_10 java.util.HashSet forEachJava8 avgt 5 5,994 ± 0,085 ns/op
CollectionIteration.benchmark_10 java.util.HashSet iterator avgt 5 5,867 ± 0,289 ns/op
CollectionIteration.benchmark_10 java.util.TreeSet forWithoutCache avgt 5 4,000 ± 0,071 ns/op
CollectionIteration.benchmark_10 java.util.TreeSet forWithCache avgt 5 5,278 ± 0,069 ns/op
CollectionIteration.benchmark_10 java.util.TreeSet forEachJava5 avgt 5 6,015 ± 0,109 ns/op
CollectionIteration.benchmark_10 java.util.TreeSet forEachJava8 avgt 5 6,523 ± 0,189 ns/op
CollectionIteration.benchmark_10 java.util.TreeSet iterator avgt 5 5,915 ± 0,310 ns/op
CollectionIteration.benchmark_10 java.util.ArrayList forWithoutCache avgt 5 5,819 ± 0,181 ns/op
CollectionIteration.benchmark_10 java.util.ArrayList forWithCache avgt 5 5,252 ± 0,618 ns/op
CollectionIteration.benchmark_10 java.util.ArrayList forEachJava5 avgt 5 4,970 ± 0,094 ns/op
CollectionIteration.benchmark_10 java.util.ArrayList forEachJava8 avgt 5 5,006 ± 0,419 ns/op
CollectionIteration.benchmark_10 java.util.ArrayList iterator avgt 5 4,595 ± 0,115 ns/op
CollectionIteration.benchmark_10 java.util.LinkedList forWithoutCache avgt 5 5,910 ± 0,202 ns/op
CollectionIteration.benchmark_10 java.util.LinkedList forWithCache avgt 5 5,114 ± 0,062 ns/op
CollectionIteration.benchmark_10 java.util.LinkedList forEachJava5 avgt 5 5,212 ± 0,033 ns/op
CollectionIteration.benchmark_10 java.util.LinkedList forEachJava8 avgt 5 5,151 ± 0,044 ns/op
CollectionIteration.benchmark_10 java.util.LinkedList iterator avgt 5 5,221 ± 0,229 ns/op
CollectionIteration.benchmark_100 java.util.HashSet forWithoutCache avgt 5 5,200 ± 0,123 ns/op
CollectionIteration.benchmark_100 java.util.HashSet forWithCache avgt 5 4,423 ± 0,028 ns/op
CollectionIteration.benchmark_100 java.util.HashSet forEachJava5 avgt 5 5,332 ± 0,070 ns/op
CollectionIteration.benchmark_100 java.util.HashSet forEachJava8 avgt 5 6,099 ± 0,874 ns/op
CollectionIteration.benchmark_100 java.util.HashSet iterator avgt 5 6,250 ± 0,042 ns/op
CollectionIteration.benchmark_100 java.util.TreeSet forWithoutCache avgt 5 3,201 ± 0,048 ns/op
CollectionIteration.benchmark_100 java.util.TreeSet forWithCache avgt 5 4,475 ± 0,171 ns/op
CollectionIteration.benchmark_100 java.util.TreeSet forEachJava5 avgt 5 5,515 ± 0,039 ns/op
CollectionIteration.benchmark_100 java.util.TreeSet forEachJava8 avgt 5 5,567 ± 0,062 ns/op
CollectionIteration.benchmark_100 java.util.TreeSet iterator avgt 5 5,441 ± 0,358 ns/op
CollectionIteration.benchmark_100 java.util.ArrayList forWithoutCache avgt 5 4,545 ± 0,126 ns/op
CollectionIteration.benchmark_100 java.util.ArrayList forWithCache avgt 5 4,493 ± 0,125 ns/op
CollectionIteration.benchmark_100 java.util.ArrayList forEachJava5 avgt 5 4,187 ± 0,134 ns/op
CollectionIteration.benchmark_100 java.util.ArrayList forEachJava8 avgt 5 4,140 ± 0,111 ns/op
CollectionIteration.benchmark_100 java.util.ArrayList iterator avgt 5 4,096 ± 0,587 ns/op
CollectionIteration.benchmark_100 java.util.LinkedList forWithoutCache avgt 5 5,997 ± 2,523 ns/op
CollectionIteration.benchmark_100 java.util.LinkedList forWithCache avgt 5 4,908 ± 0,096 ns/op
CollectionIteration.benchmark_100 java.util.LinkedList forEachJava5 avgt 5 5,059 ± 1,531 ns/op
CollectionIteration.benchmark_100 java.util.LinkedList forEachJava8 avgt 5 4,701 ± 0,229 ns/op
CollectionIteration.benchmark_100 java.util.LinkedList iterator avgt 5 4,561 ± 0,093 ns/op
CollectionIteration.benchmark_100_000 java.util.HashSet forWithoutCache avgt 5 4,300 ± 3,529 ns/op
CollectionIteration.benchmark_100_000 java.util.HashSet forWithCache avgt 5 4,633 ± 0,121 ns/op
CollectionIteration.benchmark_100_000 java.util.HashSet forEachJava5 avgt 5 6,945 ± 4,538 ns/op
CollectionIteration.benchmark_100_000 java.util.HashSet forEachJava8 avgt 5 7,395 ± 3,304 ns/op
CollectionIteration.benchmark_100_000 java.util.HashSet iterator avgt 5 6,915 ± 4,615 ns/op
CollectionIteration.benchmark_100_000 java.util.TreeSet forWithoutCache avgt 5 2,985 ± 0,047 ns/op
CollectionIteration.benchmark_100_000 java.util.TreeSet forWithCache avgt 5 4,649 ± 0,150 ns/op
CollectionIteration.benchmark_100_000 java.util.TreeSet forEachJava5 avgt 5 18,861 ± 6,052 ns/op
CollectionIteration.benchmark_100_000 java.util.TreeSet forEachJava8 avgt 5 20,552 ± 1,754 ns/op
CollectionIteration.benchmark_100_000 java.util.TreeSet iterator avgt 5 19,731 ± 1,744 ns/op
CollectionIteration.benchmark_100_000 java.util.ArrayList forWithoutCache avgt 5 4,229 ± 3,076 ns/op
CollectionIteration.benchmark_100_000 java.util.ArrayList forWithCache avgt 5 4,578 ± 0,062 ns/op
CollectionIteration.benchmark_100_000 java.util.ArrayList forEachJava5 avgt 5 4,176 ± 0,355 ns/op
CollectionIteration.benchmark_100_000 java.util.ArrayList forEachJava8 avgt 5 3,929 ± 0,134 ns/op
CollectionIteration.benchmark_100_000 java.util.ArrayList iterator avgt 5 3,933 ± 0,005 ns/op
CollectionIteration.benchmark_100_000 java.util.LinkedList forWithoutCache avgt 5 4,216 ± 3,007 ns/op
CollectionIteration.benchmark_100_000 java.util.LinkedList forWithCache avgt 5 4,576 ± 0,070 ns/op
CollectionIteration.benchmark_100_000 java.util.LinkedList forEachJava5 avgt 5 4,900 ± 0,054 ns/op
CollectionIteration.benchmark_100_000 java.util.LinkedList forEachJava8 avgt 5 5,164 ± 0,642 ns/op
CollectionIteration.benchmark_100_000 java.util.LinkedList iterator avgt 5 4,917 ± 0,090 ns/op
CollectionIteration.benchmark_10_000 java.util.HashSet forWithoutCache avgt 5 4,914 ± 0,100 ns/op
CollectionIteration.benchmark_10_000 java.util.HashSet forWithCache avgt 5 4,626 ± 0,394 ns/op
CollectionIteration.benchmark_10_000 java.util.HashSet forEachJava5 avgt 5 4,852 ± 0,042 ns/op
CollectionIteration.benchmark_10_000 java.util.HashSet forEachJava8 avgt 5 6,067 ± 0,127 ns/op
CollectionIteration.benchmark_10_000 java.util.HashSet iterator avgt 5 5,021 ± 0,083 ns/op
CollectionIteration.benchmark_10_000 java.util.TreeSet forWithoutCache avgt 5 3,001 ± 0,364 ns/op
CollectionIteration.benchmark_10_000 java.util.TreeSet forWithCache avgt 5 4,582 ± 0,070 ns/op
CollectionIteration.benchmark_10_000 java.util.TreeSet forEachJava5 avgt 5 8,483 ± 0,191 ns/op
CollectionIteration.benchmark_10_000 java.util.TreeSet forEachJava8 avgt 5 8,329 ± 0,430 ns/op
CollectionIteration.benchmark_10_000 java.util.TreeSet iterator avgt 5 8,429 ± 0,214 ns/op
CollectionIteration.benchmark_10_000 java.util.ArrayList forWithoutCache avgt 5 4,598 ± 0,078 ns/op
CollectionIteration.benchmark_10_000 java.util.ArrayList forWithCache avgt 5 4,579 ± 0,053 ns/op
CollectionIteration.benchmark_10_000 java.util.ArrayList forEachJava5 avgt 5 4,072 ± 0,031 ns/op
CollectionIteration.benchmark_10_000 java.util.ArrayList forEachJava8 avgt 5 3,869 ± 0,415 ns/op
CollectionIteration.benchmark_10_000 java.util.ArrayList iterator avgt 5 3,936 ± 0,026 ns/op
CollectionIteration.benchmark_10_000 java.util.LinkedList forWithoutCache avgt 5 4,595 ± 0,029 ns/op
CollectionIteration.benchmark_10_000 java.util.LinkedList forWithCache avgt 5 4,585 ± 0,046 ns/op
CollectionIteration.benchmark_10_000 java.util.LinkedList forEachJava5 avgt 5 4,349 ± 0,065 ns/op
CollectionIteration.benchmark_10_000 java.util.LinkedList forEachJava8 avgt 5 4,313 ± 0,054 ns/op
CollectionIteration.benchmark_10_000 java.util.LinkedList iterator avgt 5 4,340 ± 0,303 ns/op
CollectionIteration.benchmark_1_000 java.util.HashSet forWithoutCache avgt 5 4,345 ± 0,044 ns/op
CollectionIteration.benchmark_1_000 java.util.HashSet forWithCache avgt 5 4,330 ± 0,070 ns/op
CollectionIteration.benchmark_1_000 java.util.HashSet forEachJava5 avgt 5 6,577 ± 0,112 ns/op
CollectionIteration.benchmark_1_000 java.util.HashSet forEachJava8 avgt 5 7,198 ± 0,104 ns/op
CollectionIteration.benchmark_1_000 java.util.HashSet iterator avgt 5 6,769 ± 0,052 ns/op
CollectionIteration.benchmark_1_000 java.util.TreeSet forWithoutCache avgt 5 3,071 ± 0,290 ns/op
CollectionIteration.benchmark_1_000 java.util.TreeSet forWithCache avgt 5 3,679 ± 0,066 ns/op
CollectionIteration.benchmark_1_000 java.util.TreeSet forEachJava5 avgt 5 7,119 ± 0,094 ns/op
CollectionIteration.benchmark_1_000 java.util.TreeSet forEachJava8 avgt 5 7,132 ± 0,122 ns/op
CollectionIteration.benchmark_1_000 java.util.TreeSet iterator avgt 5 7,233 ± 0,134 ns/op
CollectionIteration.benchmark_1_000 java.util.ArrayList forWithoutCache avgt 5 5,220 ± 1,876 ns/op
CollectionIteration.benchmark_1_000 java.util.ArrayList forWithCache avgt 5 4,320 ± 0,024 ns/op
CollectionIteration.benchmark_1_000 java.util.ArrayList forEachJava5 avgt 5 4,136 ± 0,042 ns/op
CollectionIteration.benchmark_1_000 java.util.ArrayList forEachJava8 avgt 5 3,947 ± 0,045 ns/op
CollectionIteration.benchmark_1_000 java.util.ArrayList iterator avgt 5 4,001 ± 0,021 ns/op
CollectionIteration.benchmark_1_000 java.util.LinkedList forWithoutCache avgt 5 4,333 ± 0,060 ns/op
CollectionIteration.benchmark_1_000 java.util.LinkedList forWithCache avgt 5 4,311 ± 0,018 ns/op
CollectionIteration.benchmark_1_000 java.util.LinkedList forEachJava5 avgt 5 3,973 ± 0,403 ns/op
CollectionIteration.benchmark_1_000 java.util.LinkedList forEachJava8 avgt 5 4,044 ± 0,060 ns/op
CollectionIteration.benchmark_1_000 java.util.LinkedList iterator avgt 5 3,943 ± 0,061 ns/op
CollectionIteration.benchmark_1_000_000 java.util.HashSet forWithoutCache avgt 5 3,106 ± 0,266 ns/op
CollectionIteration.benchmark_1_000_000 java.util.HashSet forWithCache avgt 5 2,155 ± 0,085 ns/op
CollectionIteration.benchmark_1_000_000 java.util.HashSet forEachJava5 avgt 5 7,878 ± 2,565 ns/op
CollectionIteration.benchmark_1_000_000 java.util.HashSet forEachJava8 avgt 5 8,082 ± 2,750 ns/op
CollectionIteration.benchmark_1_000_000 java.util.HashSet iterator avgt 5 7,994 ± 3,090 ns/op
CollectionIteration.benchmark_1_000_000 java.util.TreeSet forWithoutCache avgt 5 2,936 ± 0,024 ns/op
CollectionIteration.benchmark_1_000_000 java.util.TreeSet forWithCache avgt 5 2,143 ± 0,017 ns/op
CollectionIteration.benchmark_1_000_000 java.util.TreeSet forEachJava5 avgt 5 22,251 ± 0,675 ns/op
CollectionIteration.benchmark_1_000_000 java.util.TreeSet forEachJava8 avgt 5 21,190 ± 0,501 ns/op
CollectionIteration.benchmark_1_000_000 java.util.TreeSet iterator avgt 5 21,754 ± 1,414 ns/op
CollectionIteration.benchmark_1_000_000 java.util.ArrayList forWithoutCache avgt 5 2,610 ± 0,015 ns/op
CollectionIteration.benchmark_1_000_000 java.util.ArrayList forWithCache avgt 5 2,140 ± 0,015 ns/op
CollectionIteration.benchmark_1_000_000 java.util.ArrayList forEachJava5 avgt 5 4,300 ± 0,301 ns/op
CollectionIteration.benchmark_1_000_000 java.util.ArrayList forEachJava8 avgt 5 4,121 ± 0,872 ns/op
CollectionIteration.benchmark_1_000_000 java.util.ArrayList iterator avgt 5 3,943 ± 0,040 ns/op
CollectionIteration.benchmark_1_000_000 java.util.LinkedList forWithoutCache avgt 5 2,612 ± 0,035 ns/op
CollectionIteration.benchmark_1_000_000 java.util.LinkedList forWithCache avgt 5 2,144 ± 0,002 ns/op
CollectionIteration.benchmark_1_000_000 java.util.LinkedList forEachJava5 avgt 5 5,022 ± 0,484 ns/op
CollectionIteration.benchmark_1_000_000 java.util.LinkedList forEachJava8 avgt 5 5,094 ± 0,777 ns/op
CollectionIteration.benchmark_1_000_000 java.util.LinkedList iterator avgt 5 5,096 ± 0,665 ns/op
Collection Iteration 1 10 100 1000 10000 100000 1000000
array forWithoutCache 18,134±2,028 3,885±0,725 2,629±0,039 3,190±2,541 2,746±0,634 2,473±0,166 2,471±0,109
array forWithCache 17,978±6,514 3,614±0,086 2,622±0,238 2,464±0,357 2,366±0,153 2,366±0,233 2,360±0,189
list forWithoutCache 17,612±2,872 4,046±0,075 3,220±0,473 2,995±0,107 3,591±0,785 2,789±0,084 2,912±0,224
list forWithCache 19,020±6,934 3,619±0,116 2,544±0,044 2,469±0,221 2,656±1,087 2,591±1,130 2,409±0,244
# Run complete. Total time: 00:23:33
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.
Benchmark (mode) (type) Mode Cnt Score Error Units
ArrayAndListSizeCache.benchmark_1 forWithoutCache array avgt 5 18,134 ± 2,028 ns/op
ArrayAndListSizeCache.benchmark_1 forWithoutCache list avgt 5 17,612 ± 2,872 ns/op
ArrayAndListSizeCache.benchmark_1 forWithCache array avgt 5 17,978 ± 6,514 ns/op
ArrayAndListSizeCache.benchmark_1 forWithCache list avgt 5 19,020 ± 6,934 ns/op
ArrayAndListSizeCache.benchmark_10 forWithoutCache array avgt 5 3,885 ± 0,725 ns/op
ArrayAndListSizeCache.benchmark_10 forWithoutCache list avgt 5 4,046 ± 0,075 ns/op
ArrayAndListSizeCache.benchmark_10 forWithCache array avgt 5 3,614 ± 0,086 ns/op
ArrayAndListSizeCache.benchmark_10 forWithCache list avgt 5 3,619 ± 0,116 ns/op
ArrayAndListSizeCache.benchmark_100 forWithoutCache array avgt 5 2,629 ± 0,039 ns/op
ArrayAndListSizeCache.benchmark_100 forWithoutCache list avgt 5 3,220 ± 0,473 ns/op
ArrayAndListSizeCache.benchmark_100 forWithCache array avgt 5 2,622 ± 0,238 ns/op
ArrayAndListSizeCache.benchmark_100 forWithCache list avgt 5 2,544 ± 0,044 ns/op
ArrayAndListSizeCache.benchmark_100_000 forWithoutCache array avgt 5 2,473 ± 0,166 ns/op
ArrayAndListSizeCache.benchmark_100_000 forWithoutCache list avgt 5 2,789 ± 0,084 ns/op
ArrayAndListSizeCache.benchmark_100_000 forWithCache array avgt 5 2,366 ± 0,233 ns/op
ArrayAndListSizeCache.benchmark_100_000 forWithCache list avgt 5 2,591 ± 1,130 ns/op
ArrayAndListSizeCache.benchmark_10_000 forWithoutCache array avgt 5 2,746 ± 0,634 ns/op
ArrayAndListSizeCache.benchmark_10_000 forWithoutCache list avgt 5 3,591 ± 0,785 ns/op
ArrayAndListSizeCache.benchmark_10_000 forWithCache array avgt 5 2,366 ± 0,153 ns/op
ArrayAndListSizeCache.benchmark_10_000 forWithCache list avgt 5 2,656 ± 1,087 ns/op
ArrayAndListSizeCache.benchmark_1_000 forWithoutCache array avgt 5 3,190 ± 2,541 ns/op
ArrayAndListSizeCache.benchmark_1_000 forWithoutCache list avgt 5 2,995 ± 0,107 ns/op
ArrayAndListSizeCache.benchmark_1_000 forWithCache array avgt 5 2,464 ± 0,357 ns/op
ArrayAndListSizeCache.benchmark_1_000 forWithCache list avgt 5 2,469 ± 0,221 ns/op
ArrayAndListSizeCache.benchmark_1_000_000 forWithoutCache array avgt 5 2,471 ± 0,109 ns/op
ArrayAndListSizeCache.benchmark_1_000_000 forWithoutCache list avgt 5 2,912 ± 0,224 ns/op
ArrayAndListSizeCache.benchmark_1_000_000 forWithCache array avgt 5 2,360 ± 0,189 ns/op
ArrayAndListSizeCache.benchmark_1_000_000 forWithCache list avgt 5 2,409 ± 0,244 ns/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment