Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs. Set Difference Method
(version: 0)
Comparing performance of:
Lodash vs Set
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js"></script>
Script Preparation code:
var a = [1, 2, 3, 4, 5] var b = [3, 4, 5, 6, 7]
Tests:
Lodash
var c = _.difference(a, b)
Set
const set1 = new Set(a); const set2 = new Set(b); const unionSet = [...a, ...b]; const uniqueNumbers = unionSet.filter( (num) => !(set1.has(num) && set2.has(num)) );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Set
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/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
8966871.0 Ops/sec
Set
5422174.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and explain what is being tested. **Benchmark Definition** The benchmark tests two approaches to calculate the set difference between two arrays: using the `Lodash` library and using the native `Set` data structure in JavaScript. **Options Compared** The options being compared are: 1. **Lodash**: The `difference()` function from the Lodash library is used to calculate the set difference. 2. **Native Set**: A new `Set` object is created for each array, and then the union of both sets is calculated using the spread operator (`[...a, ...b]`). Finally, an array filter is applied to remove numbers that are present in both sets. **Pros and Cons** 1. **Lodash**: The pros of using Lodash include: * It's a widely used and well-maintained library with a large community. * It provides a convenient way to perform common operations like set difference. 2. **Native Set**: The pros of using native `Set` include: * It's a lightweight and efficient way to perform set operations. * It's a built-in feature in JavaScript, so no additional libraries are required. However, the cons of using Lodash for this specific benchmark are: * Adding an extra library dependency, which may introduce overhead. * The performance benefits of using native `Set` might be lost due to the indirection through Lodash. On the other hand, the pros of using native `Set` include: * No additional dependencies or overhead. * Direct access to a lightweight and efficient data structure. The cons of using native `Set` are: * It requires more manual effort to implement the set difference logic. * It may not be as convenient or readable as using Lodash. **Library Used** In this benchmark, the Lodash library is used in the following way: ```javascript var c = _.difference(a, b); ``` The purpose of the `Lodash` library is to provide a convenient way to perform common operations like set difference, union, and intersection. It allows developers to write more concise and readable code without having to implement these operations from scratch. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark that would require additional explanation. However, it's worth noting that the use of `const` and arrow functions (`(num) => !...)`) is modern JavaScript syntax, but not necessary for understanding the underlying logic.
Related benchmarks:
_.union vs native Set() implementation
Lodash union vs native Set() implementation
difference2
Lodash Difference
lodash union vs native set spread
Comments
Confirm delete:
Do you really want to delete benchmark?