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 (Fixed)
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.0
Browser:
Firefox 150
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
for in
124.5M/s
for
47.7M/s
foreach
16.9M/s
for..of
4.2M/s
View exact numbers
Test name
Executions per second
✓
for in
124,533,096 Ops/sec
for
47,702,836 Ops/sec
foreach
16,888,736 Ops/sec
for..of
4,205,926 Ops/sec
Script Preparation code:
var array = new Array(100);
Tests:
for
for (let i = 0, len = array.length; i < len; i++) { array[i]; }
foreach
array.forEach(function(i) { i; });
for in
for (let i in array) { array[i]; }
for..of
for (let i of array) { i; }