Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native reverse find vs lodash _.findLast
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.findLast
Created:
5 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': 'chandler', 'age': 39 } ]
Tests:
array find
// Native users.slice().reverse().find(function (o) { return o.age < 40; })
_.findLast
_.findLast(users, 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
_.findLast
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:128.0) Gecko/20100101 Firefox/128.0
Browser/OS:
Firefox 128 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
24600588.0 Ops/sec
_.findLast
10375119.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Overview** The provided benchmark compares two approaches to find the last element in an array that satisfies a certain condition: the traditional `concat()` method and the new ES6 spread operator (`...`). The benchmark is designed to test the performance of these two approaches in JavaScript. **Options Compared** Two options are compared: 1. **Native (slice().reverse().find())**: This approach uses the native `Array.prototype.slice()`, reverses the array using `slice()` and the `reverse()` method, and then finds the last element that satisfies the condition using the `find()` method. 2. **Lodash (_.findLast())**: This approach uses the popular JavaScript library Lodash to find the last element in the array that satisfies the condition. **Pros and Cons of Each Approach** **Native (slice().reverse().find())** Pros: * Native implementation, which means it's likely to be optimized for performance. * No additional dependencies or libraries required. Cons: * Requires manual array reversal, which can lead to unnecessary overhead. * May not perform well on large arrays due to the overhead of reversing the entire array. **Lodash (_.findLast())** Pros: * Optimized for performance by Lodash's authors. * Simplifies the implementation and reduces code complexity. Cons: * Requires an additional library (Lodash) to be included, which may add overhead. * May not provide optimal performance if the condition is complex or if the array is very large. **Library: Lodash** Lodash is a popular JavaScript library that provides a set of reusable functions for various tasks. In this case, `_findLast()` is used to find the last element in an array that satisfies a certain condition. The `_.` notation refers to the top-level namespace of the Lodash library. **Special JS Feature/Syntax** This benchmark does not use any special JavaScript features or syntax beyond the ES6 spread operator (`...`). However, it's worth noting that modern JavaScript engines and browsers support the new ES6 features, which can affect performance. **Other Alternatives** If you're interested in exploring alternative approaches, here are a few options: 1. **Underscore.js**: Another popular JavaScript library that provides similar functionality to Lodash. 2. **Array.prototype.reduce() + Array.prototype.findLast()**: An alternative implementation using `reduce()` and `findLast()` instead of the spread operator. 3. **Manual loop-based approach**: Implementing a custom loop-based solution to find the last element in the array. Keep in mind that these alternatives may have different performance characteristics or complexity profiles, so it's essential to experiment and verify their results on your specific use case.
Related benchmarks:
native find vs lodash _.find
native find vs lodash _.find..
native find vs lodash _.find_fork
native find vs [0]
native find vs for..in
Comments
Confirm delete:
Do you really want to delete benchmark?