Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
20240812-for
(version: 0)
Compare loop performance
Comparing performance of:
for vs .forEach vs for...in vs for...of vs While
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var iterations = 1000000;//, 10000000 var myArray = Array.from(Array(iterations).keys()); var total = 0;
Tests:
for
var len = myArray.length; for (let i = 0; i < len; i++) { total += myArray[i]; }
.forEach
myArray.forEach((item) => { total += item })
for...in
for (var i in myArray) { total += myArray[i]; }
for...of
for (var item of myArray) { total += item }
While
var i = myArray.length; while (i--) { total += myArray[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
for
.forEach
for...in
for...of
While
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
for
4.4 Ops/sec
.forEach
5.7 Ops/sec
for...in
2.7 Ops/sec
for...of
5.6 Ops/sec
While
4.4 Ops/sec
Related benchmarks:
Javascript: reduce VS for
Javascript: reduce VS for (modified)
for vs forEach vs for..in vs for..of (with fixed iterator item reference)
Sum array: for vs forEach vs for..in vs for..of vs reduce
Comments
Confirm delete:
Do you really want to delete benchmark?