Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for loops vs forEach test: call functions from Object.values() with 4 items
(version: 1)
Comparing performance of:
for...of vs forEach vs for (C style)
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 = {}; functions.forEach((fn, i) => functionsMap[i+""] = fn);
Tests:
for...of
const values = Object.values(functionsMap); for (const fun of values) fun();
forEach
const values = Object.values(functionsMap); values.forEach(fun => fun());
for (C style)
const values = Object.values(functionsMap); for (let i = 0; i < values.length; i++) values[i]();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for...of
forEach
for (C style)
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; rv:150.0) Gecko/20100101 Firefox/150.0
Browser/OS:
Firefox 150 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for...of
15556968.0 Ops/sec
forEach
18887886.0 Ops/sec
for (C style)
22517124.0 Ops/sec
Related benchmarks:
javascript loops
Array loop vs foreach vs map2
javascript loops small
javascript loops (foreach, for-in, for-of, for, map, reduce) 1000 items
javascript loops with reduce 3
javascript loops (bigger loops)
javascript loops v2
for loops vs forEach test: call functions from array with 4 items
for loops vs forEach test: call functions from Map() value iterator with 4 items
Comments
Confirm delete:
Do you really want to delete benchmark?