Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript Set (lol)
(version: 0)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
Tests:
Lodash Uniq
var firstEqual = []; var secondEqual = []; for (var i=0; i<=100000; i++) { firstEqual.push(i); secondEqual.push(i); } var arrayToDedup = [...firstEqual, ...secondEqual]; _.uniq(arrayToDedup);
Javascript Set
var firstEqual = new Set(); var secondEqual = new Set(); for (var i=0; i<=100000; i++) { firstEqual.add(i); secondEqual.add(i); } for (var val of secondEqual) { firstEqual.add(val) } Array.from(firstEqual)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash Uniq
Javascript Set
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):
I'll break down the provided benchmark and its options for you. **Benchmark Overview** The provided benchmark measures the performance difference between two approaches to remove duplicates from an array: using Lodash's `uniq` function and JavaScript's built-in `Set` data structure. The benchmark is designed to test which approach is faster, with more executions per second. **Approach 1: Lodash Uniq** Lodash is a popular utility library for JavaScript that provides various functions for common tasks, such as array manipulation. The `uniq` function in Lodash removes duplicate elements from an array while preserving the original order of elements. In this benchmark, the test case uses the following script: ```javascript var firstEqual = []; var secondEqual = []; for (var i = 0; i <= 100000; i++) { firstEqual.push(i); secondEqual.push(i); } var arrayToDedup = [...firstEqual, ...secondEqual]; _.uniq(arrayToDedup); ``` The pros of using Lodash's `uniq` function are: * Easy to use and understand * Provides a simple way to remove duplicates from an array However, the cons are: * Adds additional overhead due to the library itself * May not be optimized for performance **Approach 2: JavaScript Set** The other approach uses JavaScript's built-in `Set` data structure to remove duplicates. A `Set` is a collection of unique values that allows for efficient addition and lookup of elements. In this benchmark, the test case uses the following script: ```javascript var firstEqual = new Set(); var secondEqual = new Set(); for (var i = 0; i <= 100000; i++) { firstEqual.add(i); secondEqual.add(i); } for (var val of secondEqual) { firstEqual.add(val) } Array.from(firstEqual); ``` The pros of using JavaScript's `Set` data structure are: * Lightweight and efficient * Optimized for performance However, the cons are: * Requires understanding of the `Set` API and its limitations * May not preserve the original order of elements **Other Considerations** When comparing these two approaches, it's essential to consider the following factors: * Performance: How fast does each approach execute? * Code readability and maintainability: Which approach is easier to understand and modify? * Additional dependencies: Does one approach require more dependencies than the other? **Library and Syntax Used** In this benchmark, Lodash's `uniq` function is used. The `Set` data structure is a built-in JavaScript API. **Special JS Feature/Syntax** This benchmark does not use any special JavaScript features or syntax beyond what is required for the two approaches.
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash uniqBy vs Set vs Set spread
Lodash - uniq
uniqBy performance lodash vs native
Comments
Confirm delete:
Do you really want to delete benchmark?