Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for loops vs forEach test: call functions from array with 4 items
(version: 1)
Comparing performance of:
for...of vs for (C style) vs forEach
Created:
3 months ago
by:
Registered User
Go to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
var functions = [ () => Math.random() + 10, () => Math.sqrt(Math.random() * 100), () => Math.floor(Math.random() * 50), () => Math.pow(Math.random(), 2), ];
Tests:
for...of
for (const fun of functions) fun();
for (C style)
for (let i = 0; i<functions.length; i++) functions[i]();
forEach
functions.forEach(fun => fun());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for...of
for (C style)
forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Browser/OS:
Chrome 149 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
for...of
28.9M/s
forEach
27.8M/s
for (C style)
25.1M/s
View exact numbers
Test name
Executions per second
✓
for...of
28,919,976 Ops/sec
forEach
27,821,268 Ops/sec
for (C style)
25,117,292 Ops/sec
Related benchmarks
js forEach vs for..of
Array loop vs foreach (static & index)
Array loop vs foreach vs every
for vs forbackwards vs foreach vs some vs for..of 2
for loops vs forEach test: call functions from Map() value iterator with 4 items
for loops vs forEach test: call functions from Object.values() with 4 items
Comments
Confirm delete:
Do you really want to delete benchmark?