Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Filter for unique (small and large)
(version: 0)
Comparing performance of:
Set spread (small) vs Array from set (small) vs Set spread (large) vs Array from set (large)
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var smlarray = Array.from({length: 40}, () => Math.floor(Math.random() * 140)); var lrgarray = Array.from({length: 4000}, () => Math.floor(Math.random() * 140));
Tests:
Set spread (small)
const fsml = [... new Set(smlarray)]
Array from set (small)
const lsml = Array.from(new Set(smlarray))
Set spread (large)
const flrg = [... new Set(lrgarray)]
Array from set (large)
const llrg = Array.from(new Set(lrgarray))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Set spread (small)
Array from set (small)
Set spread (large)
Array from set (large)
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):
Let's break down what is tested in the provided benchmark: **Script Preparation Code** The script preparation code generates two arrays: `smlarray` and `lrgarray`. `smlarray` has 40 random integers between 0 and 139, while `lrgarray` has 4000 random integers between 0 and 139. These arrays are used to test different approaches for removing duplicates. **Options Compared** The benchmark compares four options: 1. **Spread operator (`...`) with a Set**: `const fsml = [... new Set(smlarray)]` 2. **Array.from() method with a Set**: `const lsml = Array.from(new Set(smlarray))` 3. **Spread operator (`...`) with an array literal**: `const flrg = [... new Set(lrgarray)]` 4. **Array.from() method with an array literal**: `const llrg = Array.from(new Set(lrgarray))` **Pros and Cons of Each Approach** 1. **Spread operator (`...`) with a Set**: * Pros: Simple and concise syntax. * Cons: May be slower due to the creation of a new array. 2. **Array.from() method with a Set**: * Pros: More flexible and allows for custom mapping functions. * Cons: Requires more code and may be slower than the spread operator approach. 3. **Spread operator (`...`) with an array literal**: * Pros: Simple and concise syntax, similar to option 1. * Cons: May still create a new array and use more memory than using a Set directly. 4. **Array.from() method with an array literal**: * Pros: More flexible and allows for custom mapping functions, like option 2. * Cons: Requires more code and may be slower than the spread operator approach. **Library Used** The `Set` object is used in all options to remove duplicates from the arrays. The `Array.from()` method is also used, but it's not a library itself. **Special JS Feature or Syntax** None of the approaches use any special JavaScript features or syntax beyond what is commonly used in modern JavaScript development. **Other Alternatives** If you need to test other approaches for removing duplicates, some alternatives could include: * Using `Array.prototype.filter()` method * Using a custom implementation with loops and conditional statements * Using libraries like Lodash or Underscore.js, which provide utility functions for array manipulation However, the benchmark is focused on comparing different syntaxes and approaches using built-in JavaScript features, so it's unlikely that other alternatives would be included.
Related benchmarks:
Unique values of array
Set vs Filter for unique for me
Filter vs Set (unique elements)
Diff size Set vs Filter for unique
Set from array vs array Filter unique
Comments
Confirm delete:
Do you really want to delete benchmark?