Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs for (with length) vs for (reverse with length) vs every vs forEach with small array 2
(version: 0)
Comparing performance of:
for vs for (reverse with length) vs some vs every vs forEach vs for (with length)
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function generateTestArray() { var result = []; for (let i = 0; i < 100; ++i) { result.push({ a: i, b: i / 2, r: 0, }); } return result; } var array = generateTestArray();
Tests:
for
for (var i = 0; i < array.length; i++) { array[i]; }
for (reverse with length)
var length = array.length; for (var i = length; --i >= 0;) { array[i]; }
some
array.some(function(i) { array[i]; return false; });
every
array.every(function(i) { array[i]; return true; });
forEach
array.forEach(function(i) { array[i]; });
for (with length)
var length = array.length; for (var i = 0; i < length; i++) { let r = array[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
for
for (reverse with length)
some
every
forEach
for (with 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:
Regular for vs forEach
Loop Test (forEach vs for)
foreach vs for...of
for of vs forEach with console log
For loop vs <Array>.forEach() vs for...of loop
Comments
Confirm delete:
Do you really want to delete benchmark?