Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for loops vs forEach test: call functions from new array with 4 items and increment number
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Browser:
Chrome 149
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one month ago
Test name
Executions per second
for...of
21373378.0 Ops/sec
forEach
19352772.0 Ops/sec
for (C style)
21734386.0 Ops/sec
Tests:
for...of
let num = 0; const functions = [ () => Math.random() + 10, () => Math.sqrt(Math.random() * 100), () => Math.floor(Math.random() * 50), () => Math.pow(Math.random(), 2), ].map(i => i); for (const fun of functions) { fun(); num++; };
forEach
let num = 0; const functions = [ () => Math.random() + 10, () => Math.sqrt(Math.random() * 100), () => Math.floor(Math.random() * 50), () => Math.pow(Math.random(), 2), ].map(i => i); functions.forEach(fun => { fun(); num++; });
for (C style)
let num = 0; const functions = [ () => Math.random() + 10, () => Math.sqrt(Math.random() * 100), () => Math.floor(Math.random() * 50), () => Math.pow(Math.random(), 2), ].map(i => i); for (let i = 0; i < functions.length; i++) { functions[i](); num++; };