Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set vs uniq(ramda)
(version: 0)
Comparing performance of:
Usando o set vs Usando uniq
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//cdn.jsdelivr.net/npm/ramda@0.25.0/dist/ramda.min.js"></script>
Tests:
Usando o set
const l = new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]); return l;
Usando uniq
const l = [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
Usando o set
Usando uniq
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Usando o set
10173078.0 Ops/sec
Usando uniq
24284072.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of what is tested on the provided JSON, along with the pros and cons of each approach. **Benchmark Definition** The benchmark definition represents a JavaScript microbenchmark that compares two approaches: using `Set` data structure versus using `uniq` from the Ramda library. The test aims to measure which approach performs better in terms of execution speed. **Options Compared** There are two options compared: 1. **Using Set**: This option creates a new `Set` instance and adds 14 identical elements (the number 7) to it. The `Set` data structure automatically removes duplicates, so the resulting set will have only one instance of the number 7. 2. **Using uniq from Ramda**: This option uses the `uniq` function from the Ramda library to remove duplicate elements from an array. **Pros and Cons** * **Using Set**: + Pros: Faster execution time since it removes duplicates in a single pass, reducing the overall number of iterations. + Cons: May require more memory to store the set, especially for large datasets. * **Using uniq from Ramda**: + Pros: More convenient and readable code, as it's a well-known function with a clear purpose. + Cons: May be slower than using `Set` since it iterates over the array multiple times. **Ramda Library** The Ramda library is a functional programming library for JavaScript that provides a set of higher-order functions for manipulating data. The `uniq` function in particular removes duplicate elements from an array while preserving order. **Special JS Feature or Syntax** None mentioned, but it's worth noting that the benchmark uses ES6+ syntax, which may not be supported by older browsers. **Other Alternatives** If you want to test a different approach, here are some alternatives: * Using `Array.prototype.filter` and `Array.prototype.includes`: ```javascript const l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; l = l.filter(x => l.indexOf(x) === l.lastIndexOf(x)); return l; ``` This approach is similar to using `Set`, but without creating a new data structure. * Using an external library like Lodash (not Ramda): ```javascript const _ = require('lodash'); const l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(l); ``` This approach is similar to using `uniq` from Ramda, but with a different library. The choice of approach depends on the specific use case and performance requirements.
Related benchmarks:
ramda clone vs spread
includes - ramda vs native
own uniq or ramda
Ramda Uniq Vs Set 2
Comments
Confirm delete:
Do you really want to delete benchmark?