Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash map, foreach, for vs native for and map
(version: 0)
Comparing performance of:
lodash map vs lodash forEach vs native for vs native map
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var data = Array(1000000).fill({ filtering: true, mapping: 42 });
Tests:
lodash map
const aux = []; _.map(data, el => {aux.push(el.filtering)});
lodash forEach
const aux = []; _.forEach(data, el => {aux.push(el.filtering)});
native for
const aux = []; for (let index = 0; index < data.length; index++) { const el = data[index]; aux.push(el.filtering) }
native map
const aux = []; data.map(el => {aux.push(el.filtering)})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lodash map
lodash forEach
native for
native map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser/OS:
Firefox 140 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash map
71.8 Ops/sec
lodash forEach
88.1 Ops/sec
native for
221.6 Ops/sec
native map
73.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON data and explain what's being tested. **Benchmark Definition** The benchmark is comparing four approaches: 1. **Lodash `map`**: This uses the `lodash` library to perform an array transformation using the `map` function. 2. **Lodash `forEach`**: This uses the `lodash` library to iterate over an array using the `forEach` function and push elements to a new array. 3. **Native `for` loop**: This uses a traditional `for` loop to iterate over the array and push elements to a new array. 4. **Native `map` function**: This uses the built-in JavaScript `map` function to perform an array transformation. **Options Compared** Each option is compared in terms of execution speed, measured by the number of executions per second (ExecutionsPerSecond). **Pros and Cons** 1. **Lodash `map` and `forEach`**: These use a library to simplify iteration over arrays. They are likely to be faster than native implementations because they avoid the overhead of manual loop management. 2. **Native `for` loop**: This is a traditional approach that requires manual loop management, which can lead to slower performance due to the overhead of incrementing indices and checking loop conditions. 3. **Native `map` function**: While this is built-in and optimized for performance, it may not be as efficient as using a library like Lodash, especially for large datasets. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, string manipulation, and object manipulation. In this benchmark, `lodash` is used to provide the `map` and `forEach` functions, which simplify iteration over arrays. **Special JS Feature/Syntax** None of the test cases use special JavaScript features or syntax. **Other Alternatives** If you need to iterate over an array in JavaScript, you can also use other approaches such as: * **Using a for...of loop**: This is a more modern approach that uses a `for` loop with a variable declared using the `let` keyword. * **Using `reduce()`**: This function reduces an array by applying a function to each element and returns the accumulated value. However, these alternatives may not be as straightforward to implement as the options compared in this benchmark.
Related benchmarks:
lodash map, foreach, for vs native for, map
Map: Lodash vs Native
lodash map vs native map wraig0
native map vs lodash map on large array
Comments
Confirm delete:
Do you really want to delete benchmark?