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
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/142.0.0.0 Safari/537.36
Browser:
Chrome 142
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
9 months ago
for of
27.9M/s
for
22.9M/s
forEach
19.2M/s
for in
7.2M/s
View exact numbers
Test name
Executions per second
✓
for of
27,898,054 Ops/sec
for
22,850,208 Ops/sec
forEach
19,164,918 Ops/sec
for in
7,206,603 Ops/sec
Script Preparation code:
var arr = []; function doMath(a) { return Math.log(a); } for(i=0; i<5; 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); }