Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.js(last) vs Native(at)
(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.at(-1)
Lodash.js filter
_.last(arr2)
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
185430672.0 Ops/sec
Lodash.js filter
189319376.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 Definition** The provided JSON represents a benchmark comparison between two approaches: native JavaScript and Lodash.js (a popular utility library for JavaScript). The benchmark is designed to test the performance of accessing the last element in an array using two different methods: 1. Native JavaScript approach (`arr2.at(-1)`) 2. Lodash.js filter (`_.last(arr2)`) **Options Compared** The two options being compared are: * `arr2.at(-1)`: This method uses the `at()` function to access the element at the specified index (-1, which is the last index in the array). The native JavaScript implementation provides a direct and efficient way to access the last element. * `_.last(arr2)`: This method uses the Lodash.js library's `last()` function to return the last element of the array. Lodash.js provides a higher-order function that can be used with various data structures, including arrays. **Pros and Cons** Here are some pros and cons of each approach: * **Native JavaScript (`arr2.at(-1)`)**: + Pros: Direct access, efficient, and lightweight. + Cons: May not work correctly if the array is modified or has holes (e.g., `NaN` or `undefined` values). * **Lodash.js filter (`_.last(arr2)`)**: + Pros: More flexible and robust, handles edge cases like empty or modified arrays. + Cons: Adds overhead due to the use of a library function. **Library Usage** In this benchmark, Lodash.js is used for its `last()` function. Lodash.js is a popular utility library that provides various functions for tasks like array manipulation, object manipulation, and more. The `last()` function returns the last element of an array or the last element of a value (if it's not an array). In this benchmark, Lodash.js is used to provide a standardized way of accessing the last element in arrays. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark. The code uses standard JavaScript syntax and libraries like Lodash.js. **Other Alternatives** If you're interested in testing alternative approaches, here are some other options: * Use a different library for array manipulation, such as Array.prototype.at() (available in modern browsers). * Implement your own solution using a loop or recursion to access the last element of an array. * Test the performance of different data structures, like linked lists or trees. Keep in mind that each approach has its trade-offs and may not be suitable for all use cases. The MeasureThat.net benchmark provides a convenient way to compare performance between different approaches and libraries.
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js vs Native _.min
Lodash.js vs Native forked
Lodash.js vs Native1
Comments
Confirm delete:
Do you really want to delete benchmark?