Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find Last
(version: 0)
Comparing performance of:
Native vs lodash vs revert native
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 arr = []; for (var i = 0; i <= 10000000; i++) { if (i % 2 === 0) { arr.push(5); } else { arr.push(i); } } //var arr2 = Array.from({ length: 10000000}, (_, index) => { // if (index % 2 === 0) { arr.push(5); } else { arr.push(index); } //})
Tests:
Native
arr.findLast(function (element) { element === 5 });
lodash
_.findLast(arr, function (element) { element === 5});
revert native
arr.reverse().find(function (element) { element === 5 });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native
lodash
revert native
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what is being tested. **Benchmark Definition** The `Script Preparation Code` section defines an array `arr` with 10,000,000 elements, where every even index is pushed with the value 5, and every odd index is pushed with its own value. This creates a skewed array with most of the values at the beginning. The `Html Preparation Code` includes a script tag that loads the Lodash library version 4.17.4 from a CDN. **Individual Test Cases** There are three test cases: 1. **Native**: The first test case uses the built-in JavaScript `findLast` method to find the last element in the array that equals 5. 2. **lodash**: The second test case uses the Lodash library's `findLast` function from the `_` namespace (short for underscore) to achieve the same result as the native implementation. 3. **revert native**: The third test case reverses the order of the array using the `reverse()` method and then uses the built-in JavaScript `find` method to find the last element that equals 5. **Options Compared** The three test cases compare the performance of: * Built-in JavaScript `findLast` method * Lodash library's `_findLast` function * Reversing the array and using the `find` method **Pros and Cons** 1. **Native (`findLast`)**: * Pros: No external dependencies, native implementation. * Cons: May have slower performance due to its inherent limitations (e.g., iterating over the entire array). 2. **Lodash library's `_findLast` function**: * Pros: Provides a standardized and well-maintained way of finding the last element in an array, with support for many other operations. * Cons: Adds external dependency on Lodash, may have slower performance due to its overhead (e.g., function calls). 3. **Reversing the array and using `find`**: * Pros: Can be faster than the native implementation if the array is large and most elements are not of interest. * Cons: Requires extra memory allocation and copying, may have slower performance due to the reversal operation. **Special Considerations** The test case uses some specific JavaScript features: * `_.findLast` function from Lodash library * `var arr = []` syntax (JavaScript variable declaration) **Other Alternatives** If you need to find the last element in an array, other alternatives to these implementations include: * Using a custom loop or recursion * Utilizing other libraries like `lodash-es`, `underscore`, or `ramda` * Implementing your own binary search-based algorithm Keep in mind that the choice of implementation depends on your specific requirements, performance constraints, and personal preference.
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js vs Native _.min
Lodash.js vs Native Remove Duplicates
Lodash.js vs Native MAGIC
Lodash.js vs Native1
Comments
Confirm delete:
Do you really want to delete benchmark?