Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for loops vs forEach test: call functions from Object.values() with 4 items
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0
Browser:
Firefox 150
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one month ago
Test name
Executions per second
for...of
15556968.0 Ops/sec
forEach
18887886.0 Ops/sec
for (C style)
22517124.0 Ops/sec
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]();