Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set.difference vs Filter
(version: 2)
Comparing performance of:
Set.difference vs Array.filter vs Array.filter with Set.has
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var array1 = Array.from({length: 40}, () => Math.floor(Math.random() * 140)); var array2 = Array.from({length: 20}, () => Math.floor(Math.random() * 140)); var setFromArray1 = new Set(array1) var setFromArray2 = new Set(array2)
Tests:
Set.difference
const setDiff = setFromArray1.difference(setFromArray2)
Array.filter
const arrayFilter = array1.filter(value => array2.indexOf(value))
Array.filter with Set.has
const arrayFilterWithSetHas = array1.filter(value => setFromArray2.has(value))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Set.difference
Array.filter
Array.filter with Set.has
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/118.0.0.0 Safari/537.36
Browser/OS:
Chrome 118 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set.difference
0.0 Ops/sec
Array.filter
957967.7 Ops/sec
Array.filter with Set.has
2532799.8 Ops/sec
Related benchmarks:
Set vs Filter for unique
Set vs Filter vs includes+push for unique
Set from array vs array Filter unique
Filtering test LZ
Filtering test LZ 2
Set vs Filter vs forEach for unique
Set vs Filter vs forEach vs forLoop vs filterWithSet vs map for unique
Array Diffs
Set.difference vs Filter + includes
Comments
Confirm delete:
Do you really want to delete benchmark?