Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Set.difference vs Filter
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser:
Chrome 134
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Array.filter with Set.has
4.4M/s
Set.difference
4.0M/s
Array.filter
1.0M/s
View exact numbers
Test name
Executions per second
✓
Array.filter with Set.has
4,423,274 Ops/sec
Set.difference
3,977,908 Ops/sec
Array.filter
1,010,047 Ops/sec
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))