Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array find vs lodash _.find
(version: 0)
Comparing performance of: array find vs _.find
Comparing performance of:
_.find vs array find
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.11/lodash.core.js"></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
_.find
_.find(users, function (o) { return o.age < 40; })
array find
users.find(function (o) { return o.age < 40; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.find
array find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.find
104431128.0 Ops/sec
array find
182021120.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the test cases and provide an explanation for each. **Overview** The provided benchmark is comparing the performance of two methods: `array.find()` ( native JavaScript method) and `_._find` (a method from the Lodash library). Both methods are used to find the first element in an array that satisfies a given condition. **Options compared** Two options are being compared: 1. **Native JavaScript: `users.find(function (o) { return o.age < 40; })`** * Pros: + Native code, optimized for performance. + No additional dependencies required. * Cons: + May not be as concise or expressive as other libraries. + Can be slower due to the overhead of JavaScript's call stack and execution context switching. 2. **Lodash library: `_.find(users, function (o) { return o.age < 40; })`** * Pros: + More concise and expressive syntax. + Often faster than native code due to Lodash's optimized implementations. + Can provide additional utility functions for array manipulation. * Cons: + Requires an additional dependency (the Lodash library). + May introduce overhead due to the need to import and initialize the library. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for array manipulation, object manipulation, and other data transformations. The `_._find` method is part of Lodash's "More Utils" module, which provides additional functions beyond the core utility functions. In this case, `_.find` is used to find the first element in an array that satisfies a given condition. **Other considerations** * **Native JavaScript performance**: While native code can be optimized for performance, it may not always be the fastest option due to the overhead of JavaScript's call stack and execution context switching. * **Library dependencies**: Using external libraries like Lodash can introduce additional dependencies and potential issues with version compatibility or installation. **Alternatives** If you don't want to use Lodash, you could consider using other libraries that provide similar functionality, such as: 1. **Underscore.js**: Another popular JavaScript utility library that provides a wide range of functions for array manipulation and object manipulation. 2. **Ramda**: A functional programming library that provides a different set of functions for working with arrays and objects. 3. **ES6's `find()` method**: If you're using a modern JavaScript environment, you can use the built-in `find()` method on arrays to achieve similar results. Keep in mind that each alternative has its own pros and cons, and may require changes to your code or dependencies.
Related benchmarks:
native find vs lodash _.find equal
array find vs array some
native findIndex vs lodash findIndex vs lodash find using startFrom
native find vs lodash _.find for objects equality
Comments
Confirm delete:
Do you really want to delete benchmark?