Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set 10
(version: 0)
Comparing performance of:
Set vs Array
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Tests:
Set
var l = new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]); return l;
Array
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(l);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
Array
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/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
1054470.4 Ops/sec
Array
2805186.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **Benchmark Name**: "lodash uniq vs set 10" **Description**: None provided **Script Preparation Code**: None provided **Html Preparation Code**: A script tag points to a CDN-hosted Lodash library (version 4.17.10) The benchmark consists of two individual test cases: 1. **Test Case: Set** * **Benchmark Definition**: Creates an array with repeated elements and returns it. 2. **Test Case: Array** * **Benchmark Definition**: Creates an array with repeated elements, applies `_.uniq()` from Lodash to remove duplicates, and returns the result. **Options being compared**: 1. Using a built-in JavaScript `Set` object ( native option) 2. Using Lodash's `uniq()` function on an array **Pros and Cons of each approach:** * **Native Set**: Pros: + Native performance since it's implemented in C++ by the browser. + No external dependencies or libraries needed. + Typically faster than Lodash's implementation due to being closer to the metal. * Cons: + Requires JavaScript 1.7+ support (not all browsers support this feature natively). + May require additional setup or configuration for edge cases (e.g., handling non-numeric keys). * **Lodash's uniq()**: Pros: + Wide browser support, as it's a well-maintained and widely-used library. + Handles various edge cases, like array with non-unique elements or non-numeric keys. + Can be easily customized or extended for specific use cases. * Cons: + Additional dependency on Lodash library. + May incur a performance overhead due to the additional abstraction layer. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions and helpers for tasks like array manipulation, string handling, and more. In this benchmark, `_.uniq()` is used to remove duplicates from an array. **Special JS Feature/Syntax: None mentioned** Now, let's discuss alternative approaches: 1. **Using `Array.prototype.filter()`**: Instead of using a Set or Lodash's `uniq()`, you could use the `filter()` method on an array to remove duplicates. This approach would require manual implementation and might not be as efficient as using a native Set or a well-optimized library like Lodash. 2. **Using `Array.from()` and `Set`**: You could create a new array from a Set, which removes duplicates, and then convert it back to an array if needed. This approach would require additional overhead due to the intermediate step of creating a new array. In summary, the benchmark is comparing two approaches for removing duplicates from an array: using a native JavaScript `Set` object versus Lodash's `uniq()` function on an array. The results will likely favor the native Set option due to its inherent performance advantages and minimal dependencies, but Lodash's implementation can be useful in cases where additional functionality or customization is required.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
Lodash - uniq
lodash vs ES6 uniq
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?