Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash _.union vs native Set() v3
(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) const d = c.contains(a => a===3)
Set()
var c = new Set(a, b) const d = c.has(3)
Set() convert back to array
var c = new Set(a, b)
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):
**Benchmark Overview** The provided benchmark is designed to compare the performance of Lodash's `_.union` function with native JavaScript's `Set()` data structure. **Options Compared** Two options are compared: 1. **Lodash _.union**: A custom implementation using Lodash's `_union` function. 2. **Native Set() v3**: The built-in `Set` object in JavaScript, which is implemented in C++ and optimized for performance. **Pros and Cons of Each Approach** ### Lodash _.union Pros: * Easy to use: Simply call the `_union` function with two arrays as arguments. * Familiar API: Uses a well-known library (Lodash), making it easier for developers to understand and maintain. Cons: * Performance overhead: Using a library like Lodash introduces a small performance overhead due to the need to load the library, create an instance of it, and call its functions. ### Native Set() Pros: * Optimized for performance: The `Set` object is implemented in C++ and optimized for performance, making it generally faster than any custom implementation. * Memory efficiency: Sets use a compact, memory-efficient data structure that can handle large numbers of unique elements. Cons: * Unfamiliar API: The `Set` API is not as well-known as other JavaScript objects, requiring more effort to understand and use correctly. * Limited flexibility: Sets are designed for storing unique values and do not provide the same level of control as custom array implementations. **Library and Purpose** The library used in this benchmark is Lodash, a popular JavaScript utility library that provides a wide range of functions for tasks like string manipulation, object transformation, and more. In this case, the `_union` function is used to combine two arrays into a single array with no duplicates. **Special JS Feature or Syntax** None mentioned in the provided code snippets. **Benchmark Preparation Code** The preparation code sets up two initial arrays `a` and `b`, which will be used as input for both benchmark tests. The Lodash library is loaded from a CDN using an HTML script tag. **Individual Test Cases** There are three test cases: 1. **_.union**: Tests the performance of Lodash's `_union` function. 2. **Set()**: Tests the performance of native JavaScript's `Set()` data structure. 3. **Set() convert back to array**: Tests the performance of converting a Set back into an array. **Latest Benchmark Result** The latest benchmark result shows the execution times per second for each test case, measured on a Chrome 111 browser on a Windows Desktop platform: * **Set()**: 2588013.0 executions/second * **Set() convert back to array**: 2577717.0 executions/second * **_.union**: 0.0 executions/second (likely due to the high overhead of loading and executing Lodash code) Note that the results may vary depending on the specific test environment and hardware configuration.
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?