Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs forEach vs for in vs for of (2)
for vs forEach vs for in vs for of
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
forEach
484.2 Ops/sec
for in
382.0 Ops/sec
for
339.1 Ops/sec
for of
535.7 Ops/sec
Script Preparation code:
var arr = []; function doMath(a) { return Math.log(a); } for(i=0; i<10000; i++){ arr[i] = i + 1; }
Tests:
forEach
let sum = 0; arr.forEach((value) => { sum += doMath(value); });
for in
let sum = 0; for(const index in arr) { sum += doMath(arr[index]); }
for
let sum = 0; for(var i = 0; i < arr.length; i++) { const value = arr[i]; sum += doMath(value); }
for of
let sum = 0; for(const value of arr) { sum += doMath(value); }