Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native find vs lodash findIndex
(version: 0)
Compare performance of native [].findIndex and _.findIndex
Comparing performance of:
Native find vs _.findIndex
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.5/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 find
users.find(u => u.age === 30)
_.findIndex
_.findIndex(users, u => u.age === 30)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native find
_.findIndex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:137.0) Gecko/20100101 Firefox/137.0
Browser/OS:
Firefox 137 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native find
178786912.0 Ops/sec
_.findIndex
24848544.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared options, pros and cons of those approaches, and other considerations. **Benchmark Overview** The benchmark compares the performance of two functions: native `Array.prototype.findIndex` and Lodash's `_.findIndex`. The test case uses a JavaScript array `users` containing five objects with different properties. **Options Compared** Two options are being compared: 1. **Native `Array.prototype.findIndex`**: This is a built-in JavaScript method that finds the index of the first element in an array that satisfies a provided condition. 2. **Lodash's `_.findIndex`**: This is a utility function from the Lodash library that performs a similar operation as the native `findIndex`. It takes two arguments: the array to search and a callback function. **Pros and Cons of Each Approach** 1. **Native `Array.prototype.findIndex`**: * Pros: + Built-in, so no extra dependencies are required. + Likely to be optimized for performance by the JavaScript engine. * Cons: + May not provide the same level of control or flexibility as a custom implementation. 2. **Lodash's `_.findIndex`**: * Pros: + Provides more control and flexibility over the search operation (e.g., allows for early returns, multiple conditions). + Can be useful when working with complex data structures or edge cases. * Cons: + Requires an external dependency (Lodash), which may add overhead. + May not be optimized for performance by the JavaScript engine. **Library Used: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functional programming helpers, including `_.findIndex`. It's often used to simplify code and improve readability, but in this benchmark, it's being used primarily for its search functionality. **Other Considerations** * **JS Feature/Syntax**: There are no special JS features or syntaxes being tested in this benchmark. * **Device/Platform**: The benchmark is running on a desktop browser (Chrome 91) with Windows as the operating system. If you want to compare performance across different devices or platforms, you'll need to add additional test cases. **Alternatives** If you're looking for alternatives to Lodash's `_.findIndex`, here are some options: * **Your own custom implementation**: You can implement a similar search function using native JavaScript methods (e.g., `Array.prototype.findIndex`). * **Other utility libraries**: There are other utility libraries available that provide similar functionality, such as Ramda or Underscore.js. * **Built-in JavaScript methods**: As mentioned earlier, you can use built-in JavaScript methods like `Array.prototype.findIndex`, `Array.prototype.some`, or `Array.prototype.every`. Keep in mind that each of these alternatives will have its own pros and cons, and the best choice depends on your specific use case and requirements.
Related benchmarks:
native findIndex vs lodash findIndex
Array find vs lodash _.find
native findIndex vs lodash findIndex vs lodash find
native findIndex vs lodash findIndex vs lodash find using startFrom
Comments
Confirm delete:
Do you really want to delete benchmark?