Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash difference efficiency
(version: 2)
Comparing performance of:
native (n^2) vs lodash
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js"></script>
Script Preparation code:
n = 80000 list1 = Array.from({length: n}, () => Math.floor(Math.random() * n)) list2 = Array.from({length: n}, () => Math.floor(Math.random() * n))
Tests:
native (n^2)
diff = list1.filter(v1 => list2.find(v2 => v2 === v1))
lodash
diff = _.difference(list1, list2) console.log(diff)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native (n^2)
lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native (n^2)
0.8 Ops/sec
lodash
151.7 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. **What is being tested?** The provided benchmark tests two approaches for finding the difference between two lists: the native approach using vanilla JavaScript and the approach using the popular utility library Lodash. **Options compared** The test case compares the performance of two methods: 1. **Native (n^2)**: This method uses a simple loop to filter out elements that are present in both lists, resulting in a time complexity of O(n^2) due to the nested loops. 2. **Lodash**: This method uses the `_.difference()` function from Lodash, which is designed to be efficient and optimized for performance. **Pros and cons** * **Native (n^2)**: + Pros: Easy to understand and implement. + Cons: Has a high time complexity due to nested loops, making it inefficient for large datasets. * **Lodash**: + Pros: Optimized for performance by the library authors, reducing overhead and improving efficiency. + Cons: Introduces additional dependencies (the Lodash library) and may be less intuitive to understand for those not familiar with the library. **Library** In this case, the library is Lodash, a popular JavaScript utility library that provides various functions for tasks like array manipulation, string manipulation, and more. The `_.difference()` function is specifically designed to find the difference between two arrays, making it an efficient and convenient solution. **Special JS feature or syntax** There are no special JS features or syntax being used in this benchmark that would require additional explanation. **Other alternatives** For finding differences between lists, other libraries like Underscore.js (another popular utility library) or custom implementations using JavaScript's built-in `filter()` method could be considered as alternatives. However, Lodash is widely adopted and well-maintained, making it a good choice for many use cases. The benchmark result shows that the Lodash approach outperforms the native approach by a significant margin, likely due to the optimized implementation of the `_difference()` function in Lodash.
Related benchmarks:
Unique lodash vs vanilla
Lodash, Set, Array comparison v2
Lodash, Set, Array, Native comparison
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Array.prototype.every vs Lodash every()
Comments
Confirm delete:
Do you really want to delete benchmark?