Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs const size forLoop
(version: 0)
Comparing performance of:
forEach vs for
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var gsmCells = [ { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23446, "signal_strength": -75 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 59141, "signal_strength": -76 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 6924, "signal_strength": -80 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23449, "signal_strength": -81 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23448, "signal_strength": -82 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23447, "signal_strength": -83 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23445, "signal_strength": -84 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23444, "signal_strength": -85 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23443, "signal_strength": -86 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23442, "signal_strength": -87 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23441, "signal_strength": -88 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23440, "signal_strength": -89 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23439, "signal_strength": -90 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23438, "signal_strength": -91 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23437, "signal_strength": -92 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23436, "signal_strength": -93 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23435, "signal_strength": -94 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23434, "signal_strength": -95 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23433, "signal_strength": -96 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23432, "signal_strength": -97 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23431, "signal_strength": -98 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23430, "signal_strength": -99 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23429, "signal_strength": -100 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23428, "signal_strength": -101 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23427, "signal_strength": -102 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23426, "signal_strength": -103 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23425, "signal_strength": -104 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23424, "signal_strength": -105 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23423, "signal_strength": -106 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23422, "signal_strength": -107 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23421, "signal_strength": -108 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23420, "signal_strength": -109 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23419, "signal_strength": -110 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23418, "signal_strength": -111 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23417, "signal_strength": -112 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23416, "signal_strength": -113 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23415, "signal_strength": -114 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23414, "signal_strength": -115 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23413, "signal_strength": -116 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23412, "signal_strength": -117 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23411, "signal_strength": -118 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23410, "signal_strength": -119 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23409, "signal_strength": -120 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23408, "signal_strength": -121 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23407, "signal_strength": -122 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23406, "signal_strength": -123 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23405, "signal_strength": -124 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23404, "signal_strength": -125 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23403, "signal_strength": -126 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23402, "signal_strength": -127 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23401, "signal_strength": -128 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23400, "signal_strength": -129 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23399, "signal_strength": -130 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23398, "signal_strength": -131 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23397, "signal_strength": -132 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23396, "signal_strength": -133 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23395, "signal_strength": -134 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23394, "signal_strength": -135 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23393, "signal_strength": -136 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23392, "signal_strength": -137 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23391, "signal_strength": -138 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23390, "signal_strength": -139 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23389, "signal_strength": -140 }, { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23388, "signal_strength": -141 } ];
Tests:
forEach
let max = gsmCells[0]; gsmCells.forEach( (element, index) => { if(element.signal_strength > max.signal_strength) max = element; } )
for
let max = gsmCells[0]; const a = gsmCells.length; for(let i = 0; i < a; i++){ if(gsmCells[i].signal_strength > max.signal_strength) max = gsmCells[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forEach
for
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
forEach
3676369.0 Ops/sec
for
216401.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It looks like we have some benchmarking data here! To answer the question, I'll need to extract some information from the provided JSON data. **JSON Data:** ```json { "gsmCells": [ { "countrycode": 250, "operatorid": 2, "lac": 9703, "cellid": 23398, "signal_strength": -131 }, // ... ] } ``` **Benchmark Results:** ```json [ { "Benchmark Definition": "let max = gsmCells[0];\r\n\rngsmCells.forEach(\r\n (element, index) => {\r\n if(element.signal_strength > max.signal_strength) max = element;\r\n }\r\n)", "Test Name": "forEach" }, { "Benchmark Definition": "let max = gsmCells[0];\r\nconst a = gsmCells.length;\r\nfor(let i = 0; i < a; i++){\r\n\tif(gsmCells[i].signal_strength > max.signal_strength) max = gsmCells[i];\r\n}", "Test Name": "for" } ] ``` **Raw UA String and Device Information:** ```json [ { "RawUAString": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "Browser": "Chrome 120", "DevicePlatform": "Desktop", "OperatingSystem": "Windows" }, { "RawUAString": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "Browser": "Chrome 120", "DevicePlatform": "Desktop", "OperatingSystem": "Windows" } ] ``` Now, I'll need to analyze the benchmark results and provide an answer. Can you please tell me: 1. What is the question asking about the benchmarking data? 2. Do you want me to compare the execution times of the `forEach` and `for` loops in the provided JavaScript code?
Related benchmarks:
Regular for vs forEach
Benchmark For
for vs for...of vs Array.forEach
foreach vs for vs for in
for in vs for of --
Comments
Confirm delete:
Do you really want to delete benchmark?