Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash _.union vs native Set() v2
(version: 0)
Comparing performance of:
_.union 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
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 = c.has(3)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.union
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 break down the provided benchmark and explain what's being tested. **What is tested?** The benchmark compares the performance of two approaches: 1. Lodash's `_.union` method 2. JavaScript's native `Set()` constructor Both approaches are used to merge two arrays, `a` and `b`, into a new array with unique elements. **Options compared:** * **Lodash's _.union**: This approach uses the `_.union` function from Lodash, which merges two arrays into a new array with duplicate values removed. * **Native Set() constructor**: This approach uses the JavaScript native `Set()` constructor to merge two arrays into a set, and then converts the set back into an array. **Pros and cons of each approach:** * **Lodash's _.union**: + Pros: - Easy to use and readable - Provides a consistent API for merging arrays + Cons: - May not be optimized for performance, especially for large datasets - Requires including an additional library (Lodash) * **Native Set() constructor**: + Pros: - Optimized for performance, especially for large datasets - Built-in and doesn't require any additional libraries + Cons: - May be less readable due to the need to convert back and forth between sets and arrays - Requires understanding of set operations **Library: Lodash** Lodash is a popular JavaScript utility library that provides a collection of functional programming helpers, including the `_.union` function. The library includes over 100 functions for tasks like array manipulation, object transformation, and more. **Special JS feature/syntax: None mentioned in this benchmark** However, it's worth noting that set operations are a fundamental concept in JavaScript and can be used to perform various operations on data structures, such as removing duplicates or performing union/intersection/difference operations. **Other alternatives:** * Other approaches for merging arrays might include using `Array.prototype.concat()`, `Array.prototype.filter()`, or other custom solutions. However, these options are generally less efficient than the native `Set()` constructor approach. * Some alternative libraries, like Ramda, might provide optimized implementations of array merging functions.
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?