Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native reverse find vs findLast
(version: 0)
Compare the new ES6 spread operator with the traditional concat() method
Comparing performance of:
array find vs _.findLast
Created:
one year 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
users.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
_.findLast
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
array find
24914356.0 Ops/sec
_.findLast
10591418.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **Benchmark Definition** The benchmark is comparing two approaches to find an element in an array: using the `reverse()` method followed by `find()`, and using the `_` object from Lodash with its `findLast()` function. The script preparation code defines a sample array of objects, each containing an "age" property. **Options Compared** The two options being compared are: 1. **Native Approach**: Using `users.slice().reverse().find(function (o) { return o.age < 40; })` * Pros: + Typically faster and more efficient for small to medium-sized arrays + Less memory-intensive due to the use of `slice()` instead of `reverse()` * Cons: + May perform poorly on very large arrays due to the need to create a new reversed array + Requires additional function calls, which can introduce overhead 2. **Lodash Approach**: Using `users.findLast(function (o) { return o.age < 40; })` * Pros: + Often faster and more efficient for large arrays due to the optimized implementation of `findLast()` + Reduces code duplication and makes it easier to reuse common functionality * Cons: + Requires the Lodash library, which can introduce additional dependencies + May perform slower on very small arrays due to the overhead of importing the library **Other Considerations** Both approaches have different performance characteristics depending on the size of the array. For small arrays, the native approach may be faster and more efficient. However, for large arrays, the Lodash approach may outperform the native approach. Another consideration is memory usage. The native approach uses `slice()` to create a new reversed array, which can be memory-intensive for very large arrays. In contrast, the Lodash approach uses an optimized implementation of `findLast()`, which may reduce memory usage. **Library: Lodash** Lodash (a portmanteau of "lodash" and "JavaScript") is a popular JavaScript library that provides a collection of functional programming helpers and utilities. Its `_` object contains many useful functions for tasks such as array manipulation, string manipulation, and more. The `findLast()` function from Lodash searches the array for the last element that satisfies the provided condition. **Special JS Feature/ Syntax: Spread Operator** The spread operator (`...`) is a relatively recent addition to JavaScript (introduced in ES6). It allows you to expand an object or array into new expressions, effectively creating a new copy of the original data structure. In this benchmark, the spread operator is used to create a new reversed array using `users.slice().reverse()`.
Related benchmarks:
native find vs lodash _.find
normal function find vs arrow function find
native find vs lodash _.find..
native find vs lodash _.find_fork
native find vs for..in
Comments
Confirm delete:
Do you really want to delete benchmark?