Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for loops vs forEach test: call functions from Map() value iterator with 4 items
(version: 1)
Comparing performance of:
for...of vs forEach
Created:
one month ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var functions = [ () => Math.random() + 10, () => Math.sqrt(Math.random() * 100), () => Math.floor(Math.random() * 50), () => Math.pow(Math.random(), 2), ]; var functionsMap = new Map(); functions.forEach((fn, i) => functionsMap.set(i, fn));
Tests:
for...of
for (const fun of functionsMap.values()) fun();
forEach
functionsMap.values().forEach(fun => fun());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
for...of
forEach
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month 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
Test name
Executions per second
for...of
26591118.0 Ops/sec
forEach
10978218.0 Ops/sec
Related benchmarks:
variety of loops in js
Array loop vs foreach vs map x1
Iterate Map entries
Map loop vs foreach
Array loop vs foreach vs map vs map (short)
Array loop vs foreach vs map2
Array vs Iterators
for loops vs forEach test: call functions from array 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?