Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
for vs for in vs for of vs forEach (no length)
Put array length outside of the loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
for of
4.3M/s
forEach
4.1M/s
for
1.1M/s
for in
81K/s
View exact numbers
Test name
Executions per second
✓
for of
4,325,376 Ops/sec
forEach
4,085,923 Ops/sec
for
1,140,574 Ops/sec
for in
80,595 Ops/sec
Script Preparation code:
var data = [... new Array(1000)].map((x,i) => i);
Tests:
forEach
let result = 0; data.forEach(x => { result = x; });
for of
let result = 0; for (let x of data) { result = x; }
for in
let result = 0; for (let i in data) { result = data[i]; }
for
let result = 0; let len = data.length for (let i = 0; i < len; i++) { result = data[i]; }