Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs forEach vs for in vs for of vs lodash vs for reverse (2)
(version: 0)
for vs forEach vs for in vs for of vs lodash vs for reverse
Comparing performance of:
forEach vs for in vs for vs for of vs lodash foreach vs for reverse
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
var arr = []; function doMath(a) { return Math.log(a); } for(i=0; i<10000; i++){ arr[i] = i + 1; }
Tests:
forEach
let sum = 0; arr.forEach((value) => { sum += doMath(value); });
for in
let sum = 0; for(const index in arr) { sum += doMath(arr[index]); }
for
let sum = 0; for(var i = 0; i < arr.length; i++) { const value = arr[i]; sum += doMath(value); }
for of
let sum = 0; for(const value of arr) { sum += doMath(value); }
lodash foreach
let sum = 0; _.forEach(arr, (value) => { sum += doMath(value); });
for reverse
let sum = 0; for(var i = arr.length - 1; i >= 0; i--) { const value = arr[i]; sum += doMath(value); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
forEach
for in
for
for of
lodash foreach
for reverse
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 in vs for of (2)
for vs forEach vs for in vs for of vs lodash
for vs forEach vs for in vs for of vs lodash vs for reverse (3)
Comparing sum of array elements between Native and lodash and some more for loops
Comments
Confirm delete:
Do you really want to delete benchmark?