Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map vs filter for unique properties in object
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Mobile Safari/537.36
Browser:
Chrome Mobile 121
Operating system:
Android
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
use Map
1563119.8 Ops/sec
use Filter
4669771.5 Ops/sec
Script Preparation code:
const uniqueItems = {}; const arr = [{ place: "here", name: "x", other: "other stuff1" }, { place: "there", name: "x", other: "other stuff2" }, { place: "here", name: "y", other: "other stuff4" }, { place: "here", name: "z", other: "other stuff5" } ] function getUniqueListByFilter() { return arr.filter((element) => { if (uniqueItems[element.place]) { return false; } uniqueItems[element.place] = true; return true; }); } function getUniqueListByMap() { return [...new Map(arr.map(item => [item.place, item])).values()] }
Tests:
use Map
const arr1 = getUniqueListByMap()
use Filter
const arr2 = getUniqueListByFilter()