Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
for vs foreach vs for..in vs for..of (updated)
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0.1 Safari/605.1.15
Browser:
Safari 26
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
11 months ago
Benchmark engine:
Benchmark.js
for
13.0M/s
foreach
485K/s
for..of
466K/s
for in
432K/s
View exact numbers
Test name
Executions per second
✓
for
12,986,545 Ops/sec
foreach
484,579 Ops/sec
for..of
466,242 Ops/sec
for in
432,283 Ops/sec
Script Preparation code:
const array = new Array(100);
Tests:
for
const LENGTH = array.length; for (let i = 0; i < LENGTH; i++) { array[i] = Math.random(); }
foreach
array.forEach(function(i) { array[i] = Math.random(); });
for in
for (let i in array) { array[i] = Math.random(); }
for..of
for (let i of array) { array[i] = Math.random(); }