Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native findIndex vs lodash find elem
(version: 0)
Compare performance of native [].findIndex and _.find
Comparing performance of:
Native findIndex vs _.findIndex
Created:
3 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', 'cA': {"currency": "wadd","value": 0}, 'TA': {"currency": "wadd","value": 0}, 'PA': {"currency": "wadd","value": 0} }, { 'user': 'ross', 'cA': {"currency": "wadd","value": 0}, 'TA': {"currency": "wadd","value": 0}, 'PA': {"currency": "wadd","value": 0}, 'age': 31 }, { 'user': 'chandler', 'cA': {"currency": "wadd","value": 0}, 'TA': {"currency": "wadd","value": 0}, 'PA': {"currency": "wadd","value": 0},'age': 30 }, { 'user': 'jessika','cA': {"currency": "wadd","value": 0}, 'TA': {"currency": "wadd","value": 0}, 'PA': {"currency": "wadd","value": 0}, 'age': 21 }, { 'user': 'amanda', 'cA': {"currency": "wadd","value": 0}, 'TA': {"currency": "wadd","value": 0}, 'PA': {"currency": "wadd","value": 0},'age': 17 } ]
Tests:
Native findIndex
users[users.findIndex(u => u.user === 'jessika')]
_.findIndex
_.find(users, u => u.user === 'jessika')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native findIndex
_.findIndex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 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
Native findIndex
88857768.0 Ops/sec
_.findIndex
23872866.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** The provided JSON represents two test cases that compare the performance of native JavaScript's `findIndex` method with Lodash's `_findIndex` function. **Options being compared:** 1. Native JavaScript's `findIndex` method 2. Lodash's `_findIndex` function **Pros and Cons:** * **Native JavaScript's `findIndex` method:** + Pros: - Built-in, no additional library dependencies required. - Optimized for performance in modern browsers. + Cons: - Can be slower than Lodash's implementation due to the overhead of calling a custom function. - May not perform as well on older browsers or with limited resources. * **Lodash's `_findIndex` function:** + Pros: - Highly optimized and tested, resulting in faster performance. - Provides additional functionality and tools for working with arrays. + Cons: - Requires an external library dependency (Lodash). - May not be suitable for use cases where minimizing size and weight is essential. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for working with arrays, objects, strings, numbers, and more. `_findIndex` is one of the many useful functions available in Lodash, allowing developers to find the index of the first element in an array that satisfies a given condition. **Special JS feature: none** Neither test case relies on any special JavaScript features or syntax. **Other alternatives:** If you need a lightweight alternative to `findIndex`, you can consider using the native `Array.prototype.findIndex` method without calling it as a function, like this: ```javascript const index = users.findIndex(u => u.user === 'jessika'); ``` Alternatively, if you're working in an older browser or require even more minimalism, you can use a simple `for` loop to find the desired element. Keep in mind that these alternatives might not provide the same performance as using native `findIndex` or Lodash's `_findIndex`, but they can be useful in certain situations.
Related benchmarks:
native findIndex vs lodash findIndex vs lodash find
native findIndex vs lodash findIndex vs lodash find using startFrom
native findIndex vs lodash findIndex test
native findIndex vs lodash find element
Comments
Confirm delete:
Do you really want to delete benchmark?