Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native findIndex vs lodash findIndex vs lodash find
(version: 0)
Compare performance of native [].findIndex and _.findIndex and _.find
Comparing performance of:
Native findIndex vs _.findIndex vs _.find
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 28 }, { 'user': 'ross', 'age': 31 }, { 'user': 'chandler', 'age': 30 }, { 'user': 'jessika', 'age': 21 }, { 'user': 'amanda', 'age': 17 } ]
Tests:
Native findIndex
let index = users.findIndex(u => u.age === 30) let user = users[index]
_.findIndex
let index = _.findIndex(users, u => u.age === 30) let user = users[index]
_.find
let user = _.find(users, u => u.age === 30)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native findIndex
_.findIndex
_.find
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_5_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/137.0.7151.79 Mobile/15E148 Safari/604.1
Browser/OS:
Chrome Mobile iOS 137 on iOS 18.5.0
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native findIndex
108302648.0 Ops/sec
_.findIndex
97690832.0 Ops/sec
_.find
43925340.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark test cases and explain what's being tested. **Benchmark Overview** The benchmark compares the performance of three approaches: 1. **Native `Array.prototype.findIndex`**: This method searches for the first element in an array that satisfies a specified condition. 2. **Lodash `findIndex`**: A utility function from the Lodash library, which is designed to perform similar operations as native JavaScript methods but with additional features and optimizations. 3. **Lodash `find`**: Another utility function from Lodash, this time searching for the first element that satisfies a specified condition. **Options Compared** The benchmark compares these three options because: * Native methods are often faster and more efficient than third-party libraries, especially when it comes to performance-critical applications. * Lodash provides additional features and optimizations that might be beneficial in certain scenarios, but may come at the cost of extra overhead. * `findIndex` and `find` provide a convenient interface for searching arrays with conditions, which can simplify code and improve readability. **Pros and Cons** Here are some pros and cons for each approach: * **Native `Array.prototype.findIndex`**: + Pros: Generally faster and more efficient, especially for large datasets. + Cons: May not be as convenient or readable for certain use cases. * **Lodash `findIndex`**: + Pros: Provides a standardized interface and additional features like early returns and support for multiple criteria. + Cons: Adds extra overhead due to the Lodash library. * **Lodash `find`**: + Pros: Offers a more convenient and readable way to search arrays with conditions, especially when you don't need to access the matched element. + Cons: Similar to `findIndex`, it adds extra overhead due to the Lodash library. **Library Descriptions** The benchmark uses two libraries: * **Lodash**: A popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, string manipulation, and functional programming. In this case, it's used for its `findIndex` and `find` methods. * No other libraries are mentioned in the provided code. **Special JS Features or Syntax** None of the benchmark test cases use any special JavaScript features or syntax beyond what's commonly available in modern browsers. **Other Alternatives** If you're interested in exploring alternative approaches, here are a few options: * **Manual iteration**: You could write your own loop to iterate over the array and find the matching element. This approach would be less efficient than native methods but might be more controllable. * **Using `Array.prototype.some` or `Array.prototype.every`**: These methods can be used to find elements that match a condition, but they return a boolean value instead of an index. You'd need to use additional logic to extract the matched element from the array. In conclusion, this benchmark test case provides a useful comparison between native JavaScript methods and Lodash utility functions for searching arrays with conditions. It helps developers make informed decisions about which approach to choose depending on their specific use cases and performance requirements.
Related benchmarks:
native findIndex vs lodash findIndex
Array find vs lodash _.find
native find vs lodash findIndex
native findIndex vs lodash findIndex vs lodash find using startFrom
Comments
Confirm delete:
Do you really want to delete benchmark?