Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Filter vs Reduce for unique
(version: 1)
Comparing performance of:
Set spread vs Array from set vs Filter vs Reduce
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = Array.from({length: 40}, () => Math.floor(Math.random() * 140));
Tests:
Set spread
const f = [... new Set(array)]
Array from set
const s = new Set(array) const l = Array.from(s)
Filter
const b = array.filter((i,index) => array.indexOf(i)=== index)
Reduce
const r = array.reduce((previous, current) => { if(!previous.includes(current)) { previous.push(current); } return previous; }, []);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Set spread
Array from set
Filter
Reduce
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set spread
1951500.0 Ops/sec
Array from set
1906674.9 Ops/sec
Filter
1269095.8 Ops/sec
Reduce
1482389.1 Ops/sec
Related benchmarks:
Unique
Set vs Filter for unique
Set vs Filter vs includes+push for unique
Set vs Filter for unique 40k
Set vs Filter for unique for me
Set vs Filter vs forEach for unique
Set vs Filter vs forEach vs forLoop for unique
Set vs Filter vs forEach vs forLoop vs filterWithSet vs map for unique
Set vs Filter for unique 2
Comments
Confirm delete:
Do you really want to delete benchmark?