Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash union() vs native Set() for unique primitives
(version: 0)
Comparing performance of:
_.union vs set for unique primitives vs Set() vs Set() convert back to array
Created:
3 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:
_.union vs set for unique primitives
var c = _.union(a, b)
Set()
var c = [...new Set(a, b)]
Set() convert back to array
var c = new Set(a, b) var d = Array.from(c)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.union vs set for unique primitives
Set()
Set() convert back to array
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 dive into the benchmark. **What is being tested?** The benchmark is comparing three approaches to union (combine) two arrays of primitive values: 1. Using Lodash's `union()` function 2. Using the native JavaScript `Set` data structure and converting it back to an array using `Array.from()` 3. Using the native JavaScript `Set` data structure without converting it back to an array **Options compared** The benchmark is comparing two main approaches: * **Lodash's `union()` function**: This approach uses a third-party library (Lodash) to perform the union operation. * **Native JavaScript `Set` with conversion**: This approach uses the native JavaScript `Set` data structure to store unique values and then converts it back to an array using `Array.from()`. This approach is built-in to JavaScript. **Pros and Cons** **Lodash's `union()` function:** Pros: * Easy to use and understand, as it's a well-known library with a simple API. * May be faster due to optimization by the Lodash team. Cons: * Requires including an external library, which may increase page load time. * May introduce additional overhead due to the extra library. **Native JavaScript `Set` with conversion:** Pros: * No additional dependencies or page load time. * Built-in to JavaScript, so it's a native implementation. Cons: * Can be less intuitive to use, as it requires understanding of the `Set` data structure and its methods. * May be slower due to the overhead of creating and manipulating the `Set` object. **Other considerations** * The benchmark is using Chrome 111 on Windows Desktop, so the results may not be representative for other browsers or platforms. * The use of Lodash's `union()` function might introduce additional variability in the results, as it depends on the specific version of Lodash used. * The conversion from `Set` to an array using `Array.from()` might introduce additional overhead due to the extra method call. **Library and its purpose** In this benchmark, the library is Lodash, a popular JavaScript utility library that provides a wide range of functions for tasks such as string manipulation, array manipulation, and more. The `union()` function in particular is used to combine two arrays into one, removing duplicates. **Special JS feature or syntax** There isn't any special JS feature or syntax being tested in this benchmark. It's purely about comparing different approaches to unioning arrays of primitive values.
Related benchmarks:
_.union vs native Set() implementation
Lodash union vs native Set() implementation
Lodash union vs Native Javascript
Corrected Lodash _.union vs native Set()
lodash union vs native set spread
Comments
Confirm delete:
Do you really want to delete benchmark?