Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
array iteration vs _.each vs map vs for..of vs for loop
(version: 0)
Comparing performance of:
_.each vs forEach vs map vs for..of vs for loop
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.js"></script>
Script Preparation code:
var array = ['a', 'b', 'c']
Tests:
_.each
_.each(array, (value, index) => { console.log(value) })
forEach
array.forEach((value, index) => { console.log(value) })
map
array.map((value, index) => { console.log(value) })
for..of
for (const value of array) { console.log(value) }
for loop
for (let i = 0; i < array.length; i++) { console.log(array[i]) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
_.each
forEach
map
for..of
for loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.each
76862.7 Ops/sec
forEach
81064.1 Ops/sec
map
81304.3 Ops/sec
for..of
83300.5 Ops/sec
for loop
93402.6 Ops/sec
Related benchmarks:
lodash vs for-of vs forEach
Array immutable union: lodash union vs flatten and creating a new set
array.map vs _.map
Loop over object: lodash vs Object.entries [2]
Array Map Vs Lodash Map (1)
Comments
Confirm delete:
Do you really want to delete benchmark?