Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
loop through an array
(version: 0)
Comparing performance of:
foreach with callBack vs foreach vs for with keeping length vs for vs for / of vs for / in vs map
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = []; for (let i = 0; i < 1000; ++i) { arr[i] = i; } function doSomething(value) { return Math.pow(value, 3) * 7; }
Tests:
foreach with callBack
arr.forEach(item => { doSomething(item); });
foreach
arr.forEach(doSomething);
for with keeping length
const length = arr.length; for (let i = 0; i < length; i++) { doSomething(arr[i]); }
for
for (let i = 0; i < arr.length; i++) { doSomething(arr[i]); }
for / of
for (const value of arr) { doSomething(value); }
for / in
for (const value in arr) { doSomething(value); }
map
arr.map(doSomething);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
foreach with callBack
foreach
for with keeping length
for
for / of
for / in
map
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.. of vs forEach
For and Map
Fastest iteration over array: map vs forEeach vs while vs for loop (fixed)
for loop vs forEach vs while
JS Iteration - Test1
Comments
Confirm delete:
Do you really want to delete benchmark?