Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Lodash array methods
(version: 0)
Comparing performance of:
Set vs Lodash
Created:
5 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:
Set
var c = new Set(a, b) var d = Array.from(c)
Lodash
var c = _.union(a, b) _.pull(c, 1)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
Lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
3740565.5 Ops/sec
Lodash
2684524.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark definition and test cases to understand what's being tested. **Benchmark Definition** The benchmark defines two different ways to combine arrays using Set and Lodash. The goal is to compare the performance of these two approaches. 1. **Set**: This method creates a new Set object that combines the two input arrays (`a` and `b`) and then converts it back to an array using `Array.from(c)`. Sets in JavaScript are used to store unique values, making this approach efficient for removing duplicates. 2. **Lodash**: This method uses the Lodash library's `union` function to combine the two input arrays (`a` and `b`). The resulting array is then filtered to remove a specific value (`1`) using `_.pull(c, 1)`. Lodash provides various utility functions for JavaScript, including set operations. **Options Compared** The benchmark compares the performance of two different approaches: * Set (using native JavaScript) * Lodash (using a library) **Pros and Cons** * **Set**: Pros: + Native JavaScript implementation, likely to be faster and more efficient. + No additional dependencies or overhead. * Cons: + May require more manual effort to implement and optimize. * **Lodash**: Pros: + Provides a convenient and well-maintained set of utility functions, including set operations. + Can simplify code and reduce typing. * Cons: + Adds an additional dependency (Lodash) and potential overhead. **Library: Lodash** Lodash is a popular JavaScript library that provides a wide range of utility functions for tasks such as array manipulation, object transformation, and more. The `union` function used in the benchmark is part of Lodash's set operations module, which allows developers to combine arrays and remove duplicates efficiently. **Special JS Feature/Syntax** There are no special JavaScript features or syntax mentioned in this benchmark. The focus is on comparing two different approaches: native JavaScript Set and Lodash's `union` function. **Other Alternatives** If you're interested in exploring other alternatives, here are a few options: * **Native JavaScript Array.prototype.reduce()**: Instead of using a Set, you could use the `reduce()` method to combine the arrays and remove duplicates. This approach might be more concise but may not be as efficient as using a native Set. * **Preact or Immutable.js**: These libraries provide immutable data structures that can help simplify array operations and reduce the need for manual updates. However, they add additional dependencies and overhead compared to native JavaScript or Lodash. In summary, the benchmark compares the performance of two approaches: native JavaScript Set and Lodash's `union` function. The Set approach is likely to be faster and more efficient due to its native implementation, while Lodash provides a convenient but potentially slower alternative with added dependencies and overhead.
Related benchmarks:
_.union vs native Set() implementation
Array immutable union: lodash union vs flatten and creating a new set
Array immutable union: set from lodash union vs set from lodash flatten
Lodash _.union vs native Set() and Set to Array
lodash union vs native set spread
Comments
Confirm delete:
Do you really want to delete benchmark?