Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of
(version: 1)
Compare loop performance
Comparing performance of:
for vs foreach vs for in vs for..of
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
let data = [ [ 1731416366378, 3 ], [ 1731416400000, 3 ], [ 1731416546584, 3 ], [ 1731416734567, 1 ], [ 1731416915539, 1 ], [ 1731417103129, 1 ], [ 1731417283810, 1 ], [ 1731417465766, 3 ], [ 1731417644518, 3 ], [ 1731417828571, 0 ], [ 1731418008276, 0 ], [ 1731418195886, 0 ], [ 1731418399363, 0 ], [ 1731418592505, 0 ], [ 1731418771085, 0 ], ]
Tests:
for
for (var i = 0; i < data.length; i++) { data[i]; }
foreach
data.forEach(function(i) { data[i]; });
for in
for (var i in data) { data[i]; }
for..of
const criticalityCount: Record<number, number> = {}; for (const [, criticality] of data) { if (criticality === 0) { continue; } if (criticality in criticalityCount) { criticalityCount[criticality]++; } else { criticalityCount[criticality] = 1; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
for
foreach
for in
for..of
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Comments
Confirm delete:
Do you really want to delete benchmark?