Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native find vs lodash 4.1.21 _.find
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.find
Created:
one year 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.21/lodash.core.js"></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
array find
// Native users.find(function (o) { return o.age < 40; })
_.find
_.find(users, 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
array find
_.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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
135534864.0 Ops/sec
_.find
63166588.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark definition and explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Definition** The benchmark is designed to compare two approaches: using the native JavaScript `find()` method versus using the `_find` function from the Lodash library. **Native JavaScript `find()` method** The native `find()` method is used in the first test case: ```javascript users.find(function (o) { return o.age < 40; }) ``` This approach uses a callback function to iterate over the array and returns the first element that satisfies the condition. The benefits of this approach include: * It's a built-in JavaScript method, so it's likely to be implemented efficiently. * It doesn't require an additional library. However, there are some potential drawbacks: * It may have performance issues due to the need for a callback function, which can lead to slower execution times compared to other approaches. * The performance may vary depending on the browser and JavaScript engine used. **Lodash `_find` function** The second test case uses the Lodash `_find` function: ```javascript _.find(users, function (o) { return o.age < 40; }) ``` This approach uses a higher-order function to iterate over the array and returns the first element that satisfies the condition. The benefits of this approach include: * It's often implemented in a more efficient way compared to the native `find()` method. * It provides additional features, such as support for multiple filters. However, there are some potential drawbacks: * It requires an additional library (Lodash), which may not be available or required by all projects. * The performance may vary depending on the browser and JavaScript engine used, but it's often considered faster than the native `find()` method. **Other considerations** In addition to these two approaches, there are other ways to achieve this functionality, such as using `Array.prototype.filter()` or `Array.prototype.forEach()`. However, they might not be directly comparable in terms of performance. For example: ```javascript const result = users.filter(function (o) { return o.age < 40; }); ``` or ```javascript users.forEach(function (o) { if (o.age < 40) console.log(o); }); ``` These approaches can be slower than the native `find()` method or the Lodash `_find` function, especially for large datasets. **Library and syntax** In this benchmark, the Lodash library is used. It's a popular utility library that provides various functions for working with arrays, objects, and more. The syntax used in this benchmark is JavaScript, specifically ES6+ syntax. The `let` keyword is used to declare variables, which is a more modern and concise way of declaring variables compared to the traditional `var` keyword. Overall, this benchmark provides an interesting comparison between two approaches: using the native JavaScript `find()` method versus using the Lodash `_find` function. By testing these approaches, developers can gain insight into the performance differences between them and choose the best approach for their specific use case.
Related benchmarks:
native find vs lodash _.find
native find vs lodash _.find..
native find vs lodash _.find_fork
Compare prototype.find vs lodash/find
native find vs for..in
Comments
Confirm delete:
Do you really want to delete benchmark?