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
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Android 14; Mobile; rv:124.0) Gecko/124.0 Firefox/124.0
Browser:
Firefox Mobile 124
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
for in
33.7M/s
for
13.1M/s
foreach
7.5M/s
for..of
1.0M/s
View exact numbers
Test name
Executions per second
✓
for in
33,724,728 Ops/sec
for
13,050,996 Ops/sec
foreach
7,475,910 Ops/sec
for..of
1,001,961 Ops/sec
Script Preparation code:
var array = new Array(100);
Tests:
for
for (var i = 0; i < array.length; i++) { array[i]; }
foreach
array.forEach(function(i) { array[i]; });
for in
for (var i in array) { array[i]; }
for..of
for (var i of array) { array[i]; }