Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ramda union vs lodash unionWith vs Set for merging without duplicates
(version: 0)
Comparing performance of:
Set vs _.unionWith vs R.unionWith
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.15/lodash.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.min.js'></script>
Tests:
Set
const first = [ {a: 3, b: 3, c: "hey"}, {a: 3, b: 2, c: "hey"}, {a: 1, b: 2, c: "bye"}, {a: 3, b: 4, c: "hey"}, {a: 2, b: 1, c: "bye"} ]; const second = [ {a: 3, b: 4, c: "hey"}, {a: 2, b: 1, c: "bye"}, {a: 4, b: 4, c: "sup"}, {a: 3, b: 3, c: "hey"} ]; return [...new Set([...first, ...second])]
_.unionWith
const first = [ {a: 3, b: 3, c: "hey"}, {a: 3, b: 2, c: "hey"}, {a: 1, b: 2, c: "bye"}, {a: 3, b: 4, c: "hey"}, {a: 2, b: 1, c: "bye"} ]; const second = [ {a: 3, b: 4, c: "hey"}, {a: 2, b: 1, c: "bye"}, {a: 4, b: 4, c: "sup"}, {a: 3, b: 3, c: "hey"} ]; return _.unionWith(first, second, _.isEqual);
R.unionWith
const first = [ {a: 3, b: 3, c: "hey"}, {a: 3, b: 2, c: "hey"}, {a: 1, b: 2, c: "bye"}, {a: 3, b: 4, c: "hey"}, {a: 2, b: 1, c: "bye"} ]; const second = [ {a: 3, b: 4, c: "hey"}, {a: 2, b: 1, c: "bye"}, {a: 4, b: 4, c: "sup"}, {a: 3, b: 3, c: "hey"} ]; return R.unionWith(R.equals, first, second);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Set
_.unionWith
R.unionWith
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/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
1632898.8 Ops/sec
_.unionWith
65713.2 Ops/sec
R.unionWith
48339.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** The benchmark measures the performance of three different approaches for merging two arrays while removing duplicates: 1. `Set`: Using the built-in `Set` data structure to merge the arrays and remove duplicates. 2. `_unionWith` (Lodash): Using the `unionWith` function from Lodash, which takes a compare function as an argument, to merge the arrays and remove duplicates. 3. `R.unionWith` (Ramda): Using the `unionWith` function from Ramda, which is similar to Lodash's version but implemented differently. **Options compared:** The three options are compared in terms of their execution speed, measured in executions per second. **Pros and Cons:** * **Set**: This approach uses a built-in data structure that is optimized for fast lookups and removal of duplicates. It is likely to be the fastest option. + Pros: Fast, efficient use of built-in data structure. + Cons: May require additional memory allocation, depending on the size of the input arrays. * **_.unionWith` (Lodash): This approach uses a compare function to determine whether an element should be included in the resulting array. It can handle cases where the elements have different types or structures. + Pros: Flexible, can handle various data structures and types. + Cons: May have slower performance due to the comparison function overhead. * `R.unionWith` (Ramda): Similar to Lodash's version, but implemented differently. May have similar pros and cons. **Library usage:** * Lodash is used in the `_unionWith` test case. Lodash is a popular JavaScript utility library that provides a wide range of functional programming helpers. * Ramda is used in the `R.unionWith` test case. Ramda is another popular functional programming library for JavaScript. **Special JS features or syntax:** There are no special JavaScript features or syntax used in this benchmark. **Other alternatives:** There are other approaches to merging arrays while removing duplicates, such as: * Using a custom implementation with loops and conditionals. * Using other libraries like Immutable.js or Cycle.js. * Using a different data structure, such as an array of objects with unique keys. However, the built-in `Set` data structure and Lodash/Ramda's `unionWith` function are likely to be the most efficient and convenient options.
Related benchmarks:
lodash merge vs deepmerge vs ramda
ramda union (-R.equals) vs lodash unionWith vs Set for merging without duplicates
Deep merge: lodash vs ramda vs Object spread
lodash merge vs deepmerge vs ramda merge
Comments
Confirm delete:
Do you really want to delete benchmark?