Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs some vs for..of vs for..in 4
(version: 0)
Compare loop performance
Comparing performance of:
for 1 vs foreach vs some vs for..of vs for..in vs for 2
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var list="186134,127,647,776,809,811,812,820,821,827,867,869,870,871,873,934,937,940,1168,1169,1190,1204,1211,1215,1263,1297,1318,1351,1391,1454,1481,1483,1486,1488,1522,1523,1602,1604,1624,1659,1664,1679,1680,1716,1717,1722,1727,1927,1930,1935,1974,1975,1976,1978,1982,1991,1992,1997,1998,2016,2087,2088,2105,2164,2166,2167,2233,2241,2244,2264,2271,2283,2291,2292,2549,2566,2567,2622,2624,2800,2801,2825,2955,2978,3000,3019,3074,3075,3076,3204,3283,3288,3291,3292,3309,3310,3315,3341,3345,3392,3413,3414,3415,3417,3429,3475,3492,3856,4035,4248,4256,4258,4393,4436,4437,4438,4447,4454,4455,4463,4476,4477,4724,4785,4786,4820,4835,4949,5111,5182,5183,5422,5426,5608,5744,5750,5755,5819,6125,6179,6195,6197,6360,6466,6511,6527,6709,7060,7110,7189,7283,7358,7375,7386,7390,7729,7752,7753,7761,7786,7913,7914,7915,7916,7917,7926,7927,7928,7935,7936,7937,7939,7954,7960,8156,8185,8192,8210,8211,8212,8213,8214,8215,8226,8345,8347,9359,9385,9391,9392,9427,9432,9434,9485,9486,9487,9488,9490,9509,9718,9719,9769,10021,10158,10271,10328,10329,10331,10332,10333,10400,10401,10402,10403,10504,10510,10553,10554,10572,10578,10581,10582,10583,10584,10588,10623,10624,10625,10626,10628,10629,10630,10631,10632,10633,10721,11307,11308,11606,11607,11608,12248,12249,12250,12252,12257,12258,12531,12532,12535,12546,12547,12551,12552,12555,12610,12613,12633,12636,12769,12774,12776,12783,12784,12794,12798,12802,12976,13017,13025,13026,13028,13034,13042,13049,13051,13054,13068,13110,13114,13129,13260,14091,14094,14106,14109,14112,14136,14140,14146,14158,14181,14182,14190,14369,14372,14379,14380,14549,14551,14552,14554,14560,14562,14578,14724,14750,14754,14756,14799,14859,14895,14896,14900,14915,15010,15045,15049,15050,15054,15056,15057,15058,15060,15061,15064,15065,15066,15068,15069,15070,15074,15076,15078,15079,15080,15081,15123,15342,15514,15521,15522,15525,15527,15529,15532,15535,15537,15547,15802,15941,15974,15999,16004,16671,16672,16681,16685,16692,16696,16697,16702,16703,16705,16710,16713,16714,16716,16717,16723,16724,16736,16737,16982,16984,16988,17013,17015,17016,17050,17061,17193,18238,18295,18337,18339,18344,18405,18407,18409,18413,18506,18509,18510,18511,18698,18700,18736,18742,18743,18744,18745,19043,19049,19050,19056,19057,19058,19059,19156,19164,19165,19166,19167,19169,19170,19683,19684,19690,19693,19694,19695,20039,20295,20296,20479,20480,20538,20539,20549,20550,20653,20658,20667,20670,21278,21846,21847,21848,21866,21869,21870,21871,21873,21874,21875,22191,22196,22197,22198,22756,22762,23506,23507,23508,23510,23511,23519,23520,23531,23541,24250,24251,24252,24255,24257,24261,24264,24945,24947,25072,25086,25128,25133,25145,25159,25170,25171,25173,25226,25240,25241,25242,25243,25244,25245,25246,25248,25249,25254,25255,25258,25259,25261,25265,25268,25269,25270,25272,25273,25276,25285,25332,25683,25685,25686,25687,25689,25690,25691,25693,25694,25695,25696,25697,28491,28493,29502,29505,29510,29583,30040,30046,30722,30723,30727,30732,30733,30753,30831,31133,31134,31153,31155,31156,31164,31165,31168,31172,31174,31176,31177,31181,31188,31198,31209,31210,31217,31219,31220,31223,31225,31227,31232,31234,31235,31244,31247,31248,31268,31269,31270,31272,31276,31318,31320,31322,31323,31328,31330,31331,31332,31333,31334,31335,31336,31340,31342,31343,31364,31367,31368,31369,31554,31562,31570,31942,32389,32391,32392,32393,32394,32395,32396,32397,32398,32399,32400,32401,32402,32403,32404,32420,32540,32541,32571,32582,32655,32656,32659,32660,32661,32662,32663,32665,32756,33204,34366,34367,35664,35665,35681,36086,36093,36101,36116,36180,36212,36293,36296,36298,36305,36320,36329,36353,36355,36403,36404,36405,36406,36407,36409,36411,36445,36447,36449,36450,36451,36453,36454,36461,36465,36474,36477,36480,36487,36491,36493,36496,36501,36502,36503,36504,36507,36508,36509,36515,36516,36518,36521,36522,36523,36530,36531,36532,36533,36534,36535,36536,36537,36538,36543,36544,36545,36546,36549,36551,36552,36557,36565,36571,36572,36573,36574,36575,36577,36578,36579,36580,36585,36586,36591,36592,36599,36600,36601,36602,36604,36605,36606,36607,36608,36611,36613,36614,36615,36616,36617,36618,36619,36620,36621,36622,36624,36625,36627,36628,36629,36630,36632,36633,36634,36635,36636,36638,36639,36641,36642,36643,36644,36645,36648,36649,36650,36659,36687,36697,36698,36699,36700,36701,36703,36704,36705,37243,37245,37672,37743,37745,37747,37749,37755,37762,37768,37772,37802,37804,37805,37806,37807,37808,37811,37812,37889,38590,39507,39894,39895,39897,40675,40734,40736,40737,40738,40956,40957,40958,40959,41129,41168,41344,41347,41349,41351,41352,41353,41354,41355,41356,41391,41392,41609,41610,42100,42102,42111,42723,42724,42727,42729,43130,43132,43256,43258,43262,43263,43265,43266,43271,43273,43433,43434,43435,43436,43437,43438,43439,43442,43443,43444,43445,43446,43448,43449,43450,43451,43452,43453,43454,43456,43459,43469,43481,43495,43502,43565,43566,43586,43587,43588,43590,43591,43592,43593,43594,43595,43611,44217,44218,44219,44311,44312,44313,44442,44504,44687,44703,44708,44930,44931,44949,45553,45554,45555,45556,45557,45558,45561,45562,45563,45564,45565,45566,45567,47572,47573,47574,47575,47576,47577,47583,47584,47585,47586,47588,47595,47596,47604,48663,49567,49890,49891,49892,49893,49895,49896,49897,49900,49904,52252,52485,52486,52487,54492,54496,54499,54500,54502,54505,54506,55043,55044,55046,55052,55064,55066,55069,55072,55076,55081,55082,55282,55290,55298,55299,55300,55301,55302,55303,55304,55306,55307,55316,55317,55318,55319,55320,55321,55325,55334,55335,55336,55343,55344,55345,55353,55354,55355,55356,55358,55359,55361,55370,55379,55388,55389,55390,55397,55407,55408,55409,55415,55433,55442,55443,55444,55445,55451,55453,55460,55461,55462,55469,55487,55505,55532,55541,55550,55577,55586,55595,55604,55613,55622,55631,55640,55658,55667,55685,55694,55695,55703,55712,55721,55730,55739,55748,55757,55766,55775,56109,56513,56524,56536,56537,56539,56548,56561,56562,56563,56564,58197,58198,58199,58481,58486,59467,62234,62236,63537,66641,66880,66882,66883,66895,66904,66916,66920,66924,66940,66952,66954,66960,66964,66967,66968,66977,66978,66979,66980,66981,66983,66985,66990,67024,67029,67032,67045,67052,67088,67098,67099,67102,67103,67104,67106,67109,67115,67120,67122,68194,68611,68745,68756,69936,69938,69941,69943,69945,69946,69947,69948,69949,69951,69952,69953,69954,70029,70030,70034,70035,70038,70054,70056,70061,70063,70064,70065,70068,71262,71263,71264,71332,71980,71981,71982,71983,71984,71985,71986,71988,71990,71991,71992,71993,71994,71995,71996,71997,75061,75081,75083,75084,75090,75092,75099,75102,75103,75104,75107,75109,75110,75111,75113,75114,75115,75116,75117,75119,75120,75121,75122,75124,75125,75127,75128,75129,75132,75133,75134,75135,75136,76157,76158,76160,76161,77171,77172,77173,77174,77175,77316,77317,77318,77319,77321,77527,77528,78186,78187,78188,78189,78190,78191,78192,78193,78196,78197,78198,78199,78200,78201,78202,78203,78204,78205,78206,78207,78208,78209,78210,78211,78212,78213,78214,78215,78216,78217,78218,78219,78222,78223,78224,78225,78226,78227,78228,78229,78230,78231,78232,78233,78234,78235,78236,78237,78238,78240,78241,78242,78243,78244,78245,78246,78247,78248,78249,78250,78251,78252,78253,78254,78255,78256,78257,78258,78259,78260,78261,78262,78263,78264,78265,78266,78267,78268,78269,78271,78272,78273,78274,78275,78276,78277,78278,78279,78280,78281,78282,78283,78284,78285,78287,78289,78290,78291,78292,78293,78294,78295,78296,78297,78298,78299,78300,78301,78302,78303,78304,78306,78307,78308,78309,78310,78311,78312,78313,78314,78315,78316,78317,78318,78319,78320,78321,78322,78323,78324,78325,78326,78327,78328,78329,78330,78331,78332,78333,78341,82012,82016,82018,82046,82048,82050,82051,82100,82101,82102,82103,82105,82106,82107,82111,82112,82113,82155,82156,82157,82158,82159,82161,82162,82165,82166,82167,82168,82169,82211,82439,82929,82931,82934,82970,82972,82973,82974,82975,85790,85812,85821,85823,85824,85826,85831,85840,85849,85850,86185,86846,86850,87402,87403,87404,87405,87406,87420,87421,87422,87423,87426,87428,87431,87432,87433,87434,87435,87436,87448,87453,87455,87458,87460,87461,87462,87463,87466,87467,87475,87476,87477,87478,87484,87488,87490,87491,87492,87493,87494,87503,87504,87505,87507,87510,87511,87513,87514,87515,87516,87518,87522,87562,87566,90480,90481,90482,90483,90484,90485,90486,90487,90497,90580,90585,93459,93463,93465,93477,93478,93493,93498,93505,93566,93568,93570,93575,93588,93625,94070,94072,94076,94077,94085,94101,94213,94263,94264,94265,94266,94267,94268,94269,94270,94272,94273,94274,94275,94276,94575,94576,94577,94578,94579,94580,94581,94582,94583,94584,94585,94586,94587,94588,94589,94590,94591,94592,98599,98600,98601,98602,98604,98605,98606,98607,98608,98609,98610,98611,98612,98613,98614,98615,98616,98793,98796,98801,98805,98809,98816,98830,98833,98841,98886,98889,98898,98899,98909,102348,106397,106398,106529,106531,106536,106559,106562,106568,106594,106595,106598,106613,106617,106620,106622,106626,106628,106631,106632,106634,106639,106643,106650,106653,106658,106661,106664,106665,106684,107218,116459,116464,116466,116467,116469,116472,116476,116481,116489,116496,116497,116502,116503,116506,116532,116538,116543,116545,116549,116556,116557,116561,116566,116569,116570,116572,116574,116580,116586,116587,116589,116591,116595,116599,116600,116602,116607,116608,116711,116712,116714,116717,117371,118781,118782,118784,118786,118787,118788,118790,118791,118792,118793,118794,118795,118797,118798,118799,118800,118801,118802,118804,118805,118806,118807,118809,118810,118811,118812,118813,118814,118815,118816,118817,118818,118819,118820,118821,118823,118826,118827,118828,118829,118830,118831,118832,118833,118834,118835,118836,118837,118850,118851,118852,118853,118856,118857,118858,118859,118860,118871,118872,118873,118885,118886,118887,118888,118889,118890,118891,118892,118893,118894,118895,118896,119331,119332,119333,119334,119335,119336,119337,119338,119339,119340,119341,119342,119343,119344,119345,119346,119347,123911,123913,123915,123917,124150,124182,124252,124277,124288,124311,124323,124350,126995,126998,127000,127019,127020,127033,127034,128884,128887,128900,128901,130064,131277,132501,132503,132504,132505,132506,132507,132921,139405,139406,139407,139408,141564,141565,141567,141568,141569,141570,141573,141575,141576,141578,141579,141589,141590,141695,142541,143898,144331,144332,144333,144334,144399,144401,144404,146666,146667,146668,146669,146989,147044,147064,147422,147423,147424,147425,147427,147428,147429,147514,147515,147516,147517,151587,151588,151589,151590,152084,152091,152682,152819,152834,152835,153018,153019,153639,153640,153643,154159,154162,154163,154700,159840,159851,159853,159855,159857,159858,159860,159861,159884,159886,159887,159891,159892,159893,159896,159912,159913,159914,159915,159916,159917,159922,159936,159939,161072,161073,161892,161918,161919,161922,161928,161930,161931,161934,161948,161949,161950,161951,161963,161964,161965,161966,161968,161975,161993,161995,161996,161998,162652,162655,163926,163928,163931,163932,163938,163939,163940,163942,163945,163946,163950,163951,163952,163953,163954,163955,163956,163957,163958,163959,163960,163961,163962,163963,163965,163966,163967,163968,163969,164265,164266,164267,164268,164271,164273,164274,164276,164277,164278,164279,164281,164292,164294,164297,164298,164301,164303,164313,164314,164315,164316,164317,164318,164319,164320,164323,164324,164328,164329,164331,164333,164334,164336,164343,164350,164351,164352,164353,164358,164359,164361,164367,164369,164387,164388,164389,164391,164392,164393,164394,164399,164401,164402,164406,164407,164417,164427,164428,164429,164430,164432,164434,164435,164436,164437,164439,164440,164441,164442,164444,164445,164446,164447,164448,164449,164464,164469,164470,164472,164473,164481,164483,164484,164492,164493,164494,164495,164496,164498,164507,164508,164509,164510,164511,164513,164514,164515,164518,164519,164520,164521,164522,164524,164526,164527,164528,164531,164536,164539,164540,164541,164542,164543,164544,164548,164549,164553,164556,164557,164558,164559,164560,164561,164562,164563,164564,164565,164566,164567,164568,164569,164570,164648,164649,164650,164651,164652,164653,164654,164656,164660,164661,164670,164671,164672,164673,164674,164676,164677,164679,164681,164684,164685,164686,164687,164690,164692,164693,164694,164699,164701,164704,164705,164706,164707,164711,164712,164714,164717,164718,164719,165564,165925,166816,166817,166819,166821,166824,166826,166828,166831,166832,166833,166834,166838,167934,167935,167936,167937,167938,167939,167941,167942,167945,167948,167949,167950,167951,167952,167953,167954,167956,167957,167958,167960,167961,167963,167966,167967,167970,167971,167972,167973,167974,167975,167976,167983,167986,167988,167990,167991,167992,167994,167996,167997,168644,169281,169282,169286,169287,170285,170286,170287,170288,170291,170294,170295,170297,170299,170300,170301,170302,170307,170309,170310,170311,170313,170314,170315,170317,170318,170320,170323,170326,170327,170339,170342,170343,170344,170345,170346,170347,170350,170353,170354,170356,170358,170359,170360,170361,170362,170363,170364,170365,170366,180165,180751,182587,182978,183421,183425,183970,184791,184808,184809,187013,187016,187017,187018,187020,187024" var array = list.split(',')
Tests:
for 1
for (var i = 0; i < array.length; i++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
some
array.some(function(i) { array[i]; });
for..of
for (var i of array) { array[i]; }
for..in
for (const i in array) { array[i]; }
for 2
for (var i = 0, n=array.length; i < n; i++) { array[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
for 1
foreach
some
for..of
for..in
for 2
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It seems like you're asking me to parse some benchmarking data and provide an analysis of the performance differences between various for loops. Here's my attempt at analyzing the data: **Benchmark Results** | Test Name | Browser | Device Platform | Operating System | Executions Per Second | | --- | --- | --- | --- | --- | | for 1 | Chrome 87 | Desktop | Linux | 3194.63427734375 | | foreach | Chrome 87 | Desktop | Linux | 5053.50341796875 | | some | Chrome 87 | Desktop | Linux | 5053.50341796875 | | for..of | Chrome 87 | Desktop | Linux | 4204.10888671875 | | for 2 | Chrome 87 | Desktop | Linux | 6229.10205078125 | **Observations** * The `for 1` test has the lowest execution rate, indicating that using an index-based loop with manual incrementation might be the slowest approach. * The `foreach` and `some` tests have similar performance, suggesting that these iterators can produce comparable results. * The `for..of` test has a higher execution rate than `foreach`, but lower than `for 2`, indicating that using an index-based loop with automatic incrementation (via the `for...of` loop) is faster than using a traditional `forEach` iterator, but slower than manually iterating through the array. * The `for 2` test has the highest execution rate, suggesting that using a traditional `for` loop with manual incrementation might be the fastest approach. **Conclusion** Based on this analysis, it appears that the performance differences between these for loops are relatively small. However, if I had to recommend an approach, I would suggest using a traditional `for` loop with manual incrementation (`for 2`) or an optimized index-based loop like `for..of`, as they seem to be the fastest approaches. Please note that this analysis is based on a limited dataset and may not represent the full range of possible use cases.
Related benchmarks:
for vs foreach vs for..of vs for..of over entries
for vs foreach vs for..of vs for..of over entries (const)
for (cache length) vs foreach vs for..in vs for..of
for vs foreach vs for..of vs for..of over entries vs for in
for vs foreach vs for..of vs for..of over entries vs for in vs for cache vs for reverse
Comments
Confirm delete:
Do you really want to delete benchmark?