Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs forEach vs for-of vs for-reverse (short array summing 2)
(version: 0)
for vs forEach vs for-of vs for-reverse
Comparing performance of:
for vs forEach vs for-of vs for-reverse vs for with cached length
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = Array.from({length: 10}, (_, index) => index);
Tests:
for
var sum = 0 for (var i = 0; i < array.length; i++) { sum += array[i]; }
forEach
var sum = 0 array.forEach(function(item) { sum += item; });
for-of
var sum = 0 for (var item of array) { sum += item; }
for-reverse
var sum = 0 for (var i = array.length; i--;) { sum += array[i]; }
for with cached length
var sum = 0 for (var i = 0, len = array.length; i < len; i++) { sum += array[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
for
forEach
for-of
for-reverse
for with cached length
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!
Related benchmarks:
for vs forEach vs for-of vs for-reverse (calculate sum)
for vs forEach vs for-of vs for-reverse vs reduce (calculate sum)
for vs forEach vs for-of vs for-reverse (short array summing)
.forEach vs for const of
Comments
Confirm delete:
Do you really want to delete benchmark?