Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native find vs lodash _.find
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.find
Created:
7 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 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:
4 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
171742128.0 Ops/sec
_.find
89561472.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what is being tested, compared, and the pros and cons of each approach. **Benchmark Overview** The benchmark compares two approaches: using the native `find` method in JavaScript with the spread operator (`...`) versus using the `_find` function from the Lodash library. The goal is to determine which approach is faster for finding an element within an array based on a certain condition. **Native Find vs Lodash _.find** The native `find` method uses the following syntax: ```javascript array.find(callback) ``` Where `callback` is a function that returns the desired element or `undefined`. The Lodash `_find` function uses the following syntax: ```javascript _.find(array, callback) ``` Both functions take two arguments: `array` and `callback`. The `callback` function takes an element from the array as an argument and returns the desired element. **Options Compared** There are two main options being compared: 1. **Native Find**: Using the native `find` method with the spread operator (`...`). ```javascript const result = users.find(function (o) { return o.age < 40; }); ``` 2. **Lodash _.find**: Using the `_find` function from Lodash. ```javascript const result = _.find(users, function (o) { return o.age < 40; }); ``` **Pros and Cons** **Native Find:** Pros: * No additional library dependency is required. * Simple syntax. Cons: * May be slower due to the overhead of using a native method that is not optimized for performance. * Limited support for complex callback functions. **Lodash _.find:** Pros: * Optimized for performance and can handle more complex callback functions. * Provides better error handling and feedback in case no element is found. Cons: * Requires an additional library dependency (Lodash). * May add overhead due to the size of the library file. **Other Considerations** * The use of the spread operator (`...`) with native `find` is a relatively new feature that may not be supported by all browsers. * Lodash is widely used and well-maintained, but it also adds an extra dependency to the project. **Library Used: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, string manipulation, and more. In this benchmark, Lodash's `_find` function is used to find an element within an array based on a condition. **Special JS Feature or Syntax** There are no special JS features or syntaxes being tested in this benchmark. The focus is solely on comparing the performance of two approaches: native `find` with spread operator versus Lodash _.find.
Related benchmarks:
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?