Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set performance
(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>
Script Preparation code:
var input = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 2, 5, 0, 8];
Tests:
Set
var l = [...new Set(input)]; return l;
Array
return _.uniq(input);
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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
2461290.0 Ops/sec
Array
4347674.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark test created on MeasureThat.net. The benchmark compares the performance of two approaches to remove duplicates from an array: using the `Set` object and using the `uniq()` function from the Lodash library. **Options Compared** Two options are compared: 1. **Using the Set object**: This approach uses the `Set` object in JavaScript, which is a collection of unique values. It creates a new `Set` instance from the input array and returns its contents. 2. **Using the uniq() function from Lodash**: This approach uses the `uniq()` function from the Lodash library, which removes duplicates from an array. **Pros and Cons** * **Using the Set object**: + Pros: Efficient use of memory, fast execution time, and a simple implementation. + Cons: Requires JavaScript to support `Set` objects (introduced in ECMAScript 2015), may not be compatible with older browsers or environments. * **Using the uniq() function from Lodash**: + Pros: Widely supported by modern browsers and environments, easy to use, and provides additional functionality beyond just removing duplicates. + Cons: Requires a library (Lodash) to be loaded, which can introduce overhead, and may not be as efficient as using `Set` objects. **Library Used** The `uniq()` function from Lodash is used in this benchmark. Lodash is a popular JavaScript utility library that provides a collection of functional programming helpers, including the `uniq()` function, which removes duplicate values from an array. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes used in this benchmark. Both approaches use standard JavaScript features and do not rely on any advanced techniques or libraries beyond what is commonly available. **Other Alternatives** If you want to test other approaches for removing duplicates from arrays, you could consider using: * `filter()` method: Remove duplicates by filtering out elements that are already present in the array. * `reduce()``` method: Remove duplicates by reducing the array to its unique values. * Using a custom implementation using loops and conditional statements. Keep in mind that each of these alternatives may have different performance characteristics, dependencies on specific JavaScript versions or libraries, and trade-offs in terms of code complexity.
Related benchmarks:
lodash uniq vs vanilla set - final
Lodash uniq vs Set to unique array
lodash uniq vs set - 3
lodash vs ES6 uniq
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?