Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of zzz
(version: 0)
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:
const array = new Array(100000); for (let i = 0; i < array.length; ++i) { array[i] = i; }
Tests:
for
let s = 0; for (var i = 0; i < array.length; i++) { s+=array[i]; }
foreach
let s = 0; array.forEach(function(n) { s+=n; });
for in
let s = 0; for (const n in array) { s+=n; }
for..of
let s = 0; for (const n of array) { s+=n; }
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?