Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test128321983213123
(version: 0)
Comparing performance of:
_.union vs Set() vs Set() convert back to array
Created:
6 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 = _.range(0, 100000, 5) var b = _.range(0, 100000, 2)
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 = Array.from(c)
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 dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is being tested?** The provided JSON represents a benchmark suite, where three individual test cases are compared: 1. `_.union(a, b)` 2. Creating a new instance of `Set()` and passing in two arrays: `a` and `b` 3. Converting the result of step 2 back to an array using `Array.from(c)` **Options being compared** In each test case, there is only one option being tested: * `_.union(a, b)` uses the Lodash library's `_.union()` function. * Creating a new instance of `Set()` and passing in two arrays: uses the built-in JavaScript `Set` constructor. * Converting the result of step 2 back to an array using `Array.from(c)`: also uses the built-in JavaScript `Set` and `Array.from()` functions. **Pros and Cons** Here are some pros and cons for each approach: 1. **_.union(a, b)**: * Pros: Easy to read and write, leveraging the power of Lodash library. * Cons: May introduce additional overhead due to the function call and potential garbage collection. 2. **Set()**: * Pros: Fast and efficient, as sets are implemented in native code. * Cons: Requires manual array handling and can be more error-prone. 3. **Set() convert back to array**: * Pros: Combines the efficiency of `Set()` with the convenience of converting back to an array using `Array.from()`. * Cons: Introduces additional overhead due to the conversion process. **Library: Lodash** The `_.union()` function is part of the Lodash library, which provides a collection of functional programming helpers. The library is widely used in JavaScript development for its utility functions and helps make code more concise and readable. **Special JS feature: none mentioned** There are no special JavaScript features or syntaxes being tested in these benchmarks. **Other alternatives** If you were to implement these tests yourself, here are some alternative approaches: * Using `Array.prototype.reduce()` instead of `_.union()` * Creating a custom implementation for the `Set` comparison * Using a different library or framework for set operations Keep in mind that these alternatives may have their own pros and cons, which would need to be evaluated based on specific use cases and performance requirements.
Related benchmarks:
Lodash vs Ramda
Lodash vs Ramda
difference2
Last Lodash Test
uniq across _, R, Set
Comments
Confirm delete:
Do you really want to delete benchmark?