Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Set vs Filter for unique (Array of Objects)
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser:
Chrome 132
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Filter + Set
4552.1 Ops/sec
Array from Map
4001.5 Ops/sec
Naive Filter
12.7 Ops/sec
Script Preparation code:
const ids = Array.from({ length: 500 }, () => Math.random().toString(16).slice(2)); var array = [...ids.map((id) => ([{ id: id, content: "foo" }, { id: id, content: "bar" }, { id: id, content: "baz" }]))].flat();
Tests:
Filter + Set
const seen = new Set(); const deduplicatedArray1 = array.filter(item => { if (seen.has(item.id)) { return false; } seen.add(item.id); return true; });
Array from Map
const deduplicatedArray2 = [ ...new Map(array.map(item => [item.id, item])).values() ];
Naive Filter
const deduplicatedArray3 = array.filter((item, index, self) => index === self.findIndex(obj => obj.id === item.id) );