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
llama3.1:latest
, generated one year ago):
Let's break down the benchmark definition and results. **Benchmark Name**: native reverse find vs native array findLast **Description**: Compare two ways to find an element in an array that meets a certain condition: using the `slice()`, `reverse()`, and `find()` methods, versus using the `findLast()` method. **Test Cases**: There are two test cases: 1. **array find**: This test uses the `users.slice().reverse().find()` method to find an element in the `users` array where the age is less than 40. 2. **array findlast**: This test uses the `users.findLast()` method (which is a part of the Lodash library) to find the last element in the `users` array that meets the same condition. **Library Used**: The Lodash library is used in this benchmark, specifically its `findLast()` function. Lodash is a popular JavaScript utility library that provides additional functions for tasks such as array manipulation, object creation, and string manipulation. **JavaScript Features/Syntax Used**: None specific to new ES6 features or syntax are used in this benchmark. **What's Being Tested**: The primary goal of this benchmark is to compare the performance of two methods for finding an element in an array that meets a certain condition: using the `find()` method after reversing the array, versus using the `findLast()` method provided by Lodash. **Pros and Cons**: * **Native Method (array find)**: + Pros: No external library dependencies. + Cons: Requires extra memory and CPU cycles to reverse the entire array before finding the element. * **Lodash Method (array findlast)**: + Pros: More efficient, as it only iterates over the array once. + Cons: Requires an additional library dependency. **Other Alternatives**: Some possible alternatives to this benchmark could be: 1. Using a simple `for` loop or `while` loop to iterate over the array and find the element manually. 2. Using other utility libraries like Underscore.js or Ramda.js, which also provide similar functionality. 3. Benchmarking different sorting algorithms to see which one performs best for this use case. **Considerations**: When designing benchmarks, it's essential to consider factors such as: * The type of data being used (e.g., small vs large arrays). * The specific conditions that need to be met (e.g., age less than 40). * The performance characteristics of different browsers and devices. * The implications for real-world use cases, where memory and CPU efficiency are crucial.
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?