Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
For vs Foreach manu
(version: 1)
Comparing performance of:
FOR vs FOREACH
Created:
one year ago
by:
Guest
Go to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ let test = 0; function globalMeasureThatScriptPrepareFunction() { test = Math.random(); } const ar = Array(100000);
Tests:
FOR
for (let i= 0; i < ar.length; i++) { globalMeasureThatScriptPrepareFunction(); }
FOREACH
ar.forEach(() => { globalMeasureThatScriptPrepareFunction(); });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
FOR
FOREACH
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 OPR/117.0.0.0
Browser/OS:
Opera 117 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
FOREACH
20K/s
FOR
2K/s
View exact numbers
Test name
Executions per second
✓
FOREACH
19,819 Ops/sec
FOR
1,535 Ops/sec
Related benchmarks
reate array by lenght
Test array concat
Test array concat with larger array
Test array ops
forEach vs for of (with Iterator)
forEach vs for of (with Iterator) 2
Joining strings 2
Joining strings 3
Joining strings 4
Comments
Confirm delete:
Do you really want to delete benchmark?