Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map: Lodash vs Array.prototype
(version: 0)
Comparing performance of:
array map vs lodash map
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.core.js"></script>
Tests:
array map
const array = [{a: 1, b: 1}, {a: 2, b:2}, {a: 3, b:3}]; array.map(a => a.a)
lodash map
const array = [{a: 1, b: 1}, {a: 2, b:2}, {a: 3, b:3}]; _.map(array, a => a.a)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array map
lodash map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 YaBrowser/24.10.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array map
105938968.0 Ops/sec
lodash map
39080524.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, the options compared, their pros and cons, and other considerations. **Benchmark Definition** The benchmark definition is a simple JavaScript code snippet that tests two different ways of mapping over an array: 1. Using the `Array.prototype.map()` method. 2. Using the `_` (Lodash) library's `map()` function. The script preparation code includes a link to include the Lodash library in the test environment, so both versions can be executed with the same dependencies. **Individual Test Cases** There are two individual test cases: 1. **"array map"`**: This test case executes the JavaScript code `const array = [{a: 1, b: 1}, {a: 2, b:2}, {a: 3, b:3}];\r\narray.map(a => a.a)` using the built-in `Array.prototype.map()` method. 2. **"lodash map"`**: This test case executes the same JavaScript code, but with the Lodash library's `_` prefix: `const array = [{a: 1, b: 1}, {a: 2, b:2}, {a: 3, b:3}];\r\n_.map(array, a => a.a)`. The test assumes that the Lodash library has already been included in the test environment. **Options Compared** The two options being compared are: * **Built-in `Array.prototype.map()` method**: This is a native JavaScript function that maps over an array and returns a new array with transformed elements. * **Lodash's `_map()` function**: This is a utility function from the Lodash library that performs the same mapping operation as the built-in `Array.prototype.map()` method. **Pros and Cons** Here are some pros and cons of each option: * **Built-in `Array.prototype.map()` method**: + Pros: - Native JavaScript function, so no additional dependencies needed. - Faster execution, since it's a native function. - More intuitive syntax for developers familiar with the built-in `map()` function. + Cons: - May not provide the same level of functionality or options as Lodash's `_map()` function. * **Lodash's `_map()` function**: + Pros: - Provides more advanced features, such as support for asynchronous mapping and partial functions. - Can be more convenient to use in certain situations, especially when working with complex data structures. + Cons: - Requires additional dependencies (the Lodash library). - May introduce performance overhead due to the extra dependency. **Other Considerations** Some other considerations to keep in mind: * **ES6 support**: The `Array.prototype.map()` method is a standard part of the ECMAScript 2015 (ES6) specification, so it's widely supported across modern browsers and Node.js environments. Lodash's `_map()` function may not be as widely supported. * **Performance overhead**: While Lodash's `_map()` function can provide more advanced features, it also introduces additional dependencies and potentially slower execution due to the overhead of loading the library. **Alternatives** If you're interested in exploring alternative options for mapping over arrays, here are a few alternatives: * **Other libraries**: There are other libraries available that provide similar functionality to Lodash's `_map()` function, such as `underscore.js` or `ramda`. * **Custom implementation**: You can also implement your own mapping function using JavaScript's native functions (e.g., `forEach()`, `reduce()`) and some creative use of closures and callback functions.
Related benchmarks:
Array.prototype.map vs Lodash map
Array.prototype.map vs Lodash.map on large data
lodash _.map vs native map true version
native map vs lodash map on large array
Array Map Vs Lodash Map (1)
Comments
Confirm delete:
Do you really want to delete benchmark?