Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash findLast vs Native findLast
(version: 0)
Comparing performance of:
Native vs Lodash.js filter
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var max1 = 100000; // 100,000 (100 Thousand) var max2 = 10000000; // 10,000,000 (10 Million) var max3 = 100000000; // 100,000,000 (100 Million) var arr1 = []; //for (var i = 0; i <= max1; i++) { arr1.push(i); } var arr2 = []; for (var i = 0; i <= max2; i++) { arr2.push(i); } var arr3 = []; //for (var i = 0; i <= max3; i++) { arr3.push(i); }
Tests:
Native
arr2.findLast(function (element) { element === 9999999 });
Lodash.js filter
_.findLast(arr2, function (element) { element === 9999999});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash.js filter
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/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
16.7 Ops/sec
Lodash.js filter
52.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **What is being tested?** The provided JSON represents two test cases: 1. `_.findLast(arr2, function (element) { element === 9999999})` - This is a JavaScript method call that uses the Lodash library to find the last element in an array (`arr2`) that matches a specific condition. 2. The native JavaScript method `arr2.findLast(function (element) { element === 9999999 })` - This is a built-in JavaScript method that achieves the same result as the first test case, but without using any external libraries. **Options compared** The two options being compared are: 1. Using the Lodash library (`_.findLast(arr2, function (element) { element === 99... } )`) 2. The native JavaScript `findLast` method (`arr2.findLast(function (element) { element === 9999999 })`) **Pros and Cons of each approach** **Lodash library:** Pros: * Convenience: Lodash provides a simple and concise way to achieve common array operations. * Testability: Lodash methods are often well-tested, reducing the risk of bugs in your own code. Cons: * Performance impact: Using an external library like Lodash can introduce additional overhead due to memory allocation, garbage collection, and other factors. * Dependence on third-party libraries: Your test case relies on the Lodash library being available and up-to-date. **Native JavaScript `findLast` method** Pros: * Performance advantage: The native `findLast` method is typically faster than a custom implementation with an external library. * No additional dependencies: Your test case only depends on the standard JavaScript API, eliminating potential issues related to third-party libraries. Cons: * Complexity: The native `findLast` method can be less straightforward to use and understand, especially for those without prior experience with it. * Limited support: Some older browsers or environments may not support this method or have limited functionality. **Other considerations** * Array construction: The benchmark creates large arrays (`arr1`, `arr2`, and `arr3`) using a loop. This can impact performance, as each iteration adds an element to the array. Consider using more efficient methods for constructing arrays. * Condition evaluation: In both test cases, the condition used to find the last element is `element === 9999999`. This comparison operation may have a significant impact on performance, especially in larger datasets. **Library and its purpose** In this case, Lodash (`_.findLast`) is a popular utility library that provides a set of methods for working with arrays, objects, numbers, and other data structures. The `_` prefix is a convention used by Lodash to distinguish its functions from the standard JavaScript API. **Special JS feature or syntax** The test cases do not explicitly use any special JavaScript features or syntax beyond the `findLast` method and array construction. However, it's essential to note that performance optimizations can often be achieved by leveraging native browser APIs, such as Web Workers or WebAssembly, which are not directly related to this benchmark. I hope this explanation helps you understand what's being tested in this benchmark!
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js vs Native _.min
Lodash.js vs Native (find)
Lodash.js(last) vs Native(at)
Lodash.js vs Native1
Comments
Confirm delete:
Do you really want to delete benchmark?