Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native reverse findIndex vs lodash _.findLastIndex
(version: 1)
Compare lodash findLastIndex with native reverse and findIndex.
Comparing performance of:
array find vs _.findLastIndex
Created:
3 years ago
by:
Registered User
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 src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var users = [ { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
array find
// Native users.slice().reverse().findIndex(function (o) { return o.age === 41; })
_.findLastIndex
_.findLastIndex(users, function (o) { return o.age === 41; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array find
_.findLastIndex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
11231049.0 Ops/sec
_.findLastIndex
4713854.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is tested on the provided JSON?** The provided JSON represents two test cases that compare the performance of native `reverse()` and `findIndex()` with the external library Lodash's `_.findLastIndex()`. The test cases are: 1. **Native**: Uses the built-in `reverse()` and `findIndex()` methods to search for an element in a reversed array. 2. **Lodash _.findLastIndex**: Uses the Lodash library's `_.findLastIndex()` function to search for an element in the same array. **Options compared** The two options are: 1. **Native**: The built-in JavaScript method using `reverse()` and `findIndex()`. 2. **Lodash _.findLastIndex**: The external library Lodash's implementation of the `_.findLastIndex()` function. **Pros and cons of each approach:** **Native** Pros: * No additional library dependency * Built-in methods, so no overhead for importing a library * Native performance, as it's implemented in the browser's engine Cons: * Requires reversing the entire array, which can be inefficient if the array is large. * Uses `findIndex()`, which returns the index of the first matching element, not the last. **Lodash _.findLastIndex** Pros: * More efficient than reversing the entire array, as it only searches until the last element. * Returns the correct result directly without needing to calculate an index. Cons: * Requires importing and loading the Lodash library, which can add overhead. * May have additional function call overhead due to the library's implementation. **Other considerations:** When choosing between these two approaches, consider the following factors: * **Array size**: If your array is very large, reversing it using `reverse()` might be inefficient. In this case, Lodash's `_findLastIndex()` might be a better choice. * **Performance-critical code**: If you're writing performance-critical code, you may want to prefer the native implementation for its potential speed advantages. * **Readability and maintainability**: If readability and maintainability are more important than performance, using Lodash's `_findLastIndex()` might make your code easier to understand. **Lodash library** The Lodash library is a popular utility library that provides many useful functions for working with JavaScript data structures. In this case, the `_.findLastIndex()` function is used to search for an element in an array from the end (last index). **Special JS features or syntax** There are no special JavaScript features or syntax mentioned in this benchmark. **Other alternatives** If you don't want to use Lodash, you can also consider implementing your own `_.findLastIndex()` function using JavaScript's built-in methods. This would involve iterating through the array from the end and finding the first matching element, which could be done without the need for an external library.
Related benchmarks:
Array find vs lodash _.find
native find vs lodash _.find equal
native findIndex vs lodash findIndex vs lodash find using startFrom
native find vs lodash _.find for objects equality
Comments
Confirm delete:
Do you really want to delete benchmark?