Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native reverse find vs native array findLast
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs array findlast
Created:
3 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 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': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'chandler', 'age': 39 } ]
Tests:
array find
// Native users.slice().reverse().find(function (o) { return o.age < 40; })
array findlast
users.slice().findLast(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
array findlast
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/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
68665960.0 Ops/sec
array findlast
40851532.0 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark on MeasureThat.net compares the performance of two methods for finding a user in an array based on their age: * **`array find`:** This approach uses `slice()` to create a copy of the `users` array, reverses it using `.reverse()`, and then employs the `.find()` method to locate the first user whose age is less than 40. * **`array findLast`:** This method directly utilizes the newer `.findLast()` function on the original `users` array to find the last user with an age less than 40. **Pros and Cons:** * **`array find`:** * **Cons:** Requires more steps, potentially impacting performance due to extra array operations. Reversing the array adds extra overhead. * **`array findLast`:** * **Pros:** More concise and efficient as it directly targets the desired element without requiring extra array manipulations. **Other Considerations:** * The benchmark doesn't factor in potential edge cases (e.g., an empty array) or variations in data size. Real-world performance might differ depending on these factors. * The `lodash` library isn't actively used in this benchmark, though it's included in the HTML preparation code for unknown reasons. **Alternatives:** 1. **Using a loop:** A traditional `for` loop could achieve the same result as `.find()` or `.findLast()`, offering fine-grained control but potentially being less efficient for large arrays. 2. **Sorting the array:** If you frequently need to find specific elements based on order, sorting the array beforehand can make searching more efficient using binary search algorithms. Let me know if you have any other questions!
Related benchmarks:
native find vs lodash _.find
normal function find vs arrow function find
native reverse find vs lodash _.findLast larger sample
native reverse find vs native array findLast vs for loop find
Comments
Confirm delete:
Do you really want to delete benchmark?