Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
A native map vs lodash _.map
(version: 0)
Comparing performance of:
array map vs _.find
Created:
4 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.11/lodash.core.js"></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
array map
// Native users.map(user => user.user);
_.find
_.find(users, (user) => user.user)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array map
_.find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array map
27348514.0 Ops/sec
_.find
27420472.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help explain the benchmark and its results. **Benchmark Overview** The provided JSON represents two JavaScript microbenchmarks that compare native JavaScript's `map` function with Lodash's `_.map` function. The benchmarks are designed to test the performance of these functions on a small dataset of user objects. **Native `map` vs Lodash `_map`** The tests compare the performance of: 1. Native JavaScript's `map` function, which applies a transformation to each element in an array and returns a new array. 2. Lodash's `_.map` function, which is a higher-order function that takes a callback function as an argument. **Pros and Cons:** * **Native `map`:** + Pros: - Built-in JavaScript function, no external dependencies required. - Typically faster execution time due to its native implementation. + Cons: - Requires explicit iteration over the array, which may lead to slower performance compared to higher-order functions like Lodash's `_map`. * **Lodash's `_map`:** + Pros: - Higher-order function that abstracts away low-level details, making it easier to write and maintain code. - Often provides additional features and optimizations not available in native `map`. + Cons: - External dependency required (Lodash library), which may introduce overhead. - May incur slower execution time due to the overhead of the higher-order function. **Other Considerations:** * **Callback functions:** Both tests use callback functions, which are a fundamental concept in functional programming. The choice of using callbacks can affect performance, readability, and maintainability of code. * **Array size:** The benchmark uses an array of three elements, which is a small dataset. Larger datasets may reveal differences in performance between native `map` and Lodash's `_map`. * **Browser vs Node.js:** The test results are reported for a Firefox browser on macOS 10.14. If you wanted to compare the performance on other platforms (e.g., Windows, Linux) or environments (e.g., Node.js), this would require additional testing. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as data manipulation, string and array operations, and more. In this benchmark, Lodash's `_.map` function is used to compare its performance with native JavaScript's `map`. **Special JS Features/Syntax: None** There are no special JavaScript features or syntax used in these tests. **Alternatives:** If you need to benchmark other JavaScript functions or libraries, consider the following alternatives: * Native JavaScript functions like `forEach`, `reduce`, and `filter`. * Other higher-order functions from libraries like Ramda or Underscore.js. * Custom implementations of map-like functions using loops or recursive function calls. Keep in mind that each alternative will have its own pros and cons, and you may need to adjust your benchmarking strategy accordingly.
Related benchmarks:
Map lodash and PureJS
_.map vs array.map
_.map vs. array.map for object
aadasdsa
Comments
Confirm delete:
Do you really want to delete benchmark?