Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Remove duplicate objects by a property
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0
Browser:
Firefox 133
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Filter and FindIndex
368.5 Ops/sec
Filter and IndexOf
396.7 Ops/sec
Lodash
860.2 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
const DATA = {} for (let keyIndex = 1; keyIndex <= 10; keyIndex++) { const key = `key${keyIndex}`; // Dynamically generate key names const objectsArray = []; for (let n = 1; n <= 10000; n++) { objectsArray.push({ id: n % 35 }); // Push objects with id: n % 35 } DATA[key] = objectsArray; // Assign the array to the key }
Tests:
Filter and FindIndex
const groupedWithoutDuplicates = {} Object.keys(DATA).forEach((key) => { groupedWithoutDuplicates[key] = DATA[key].filter( (item, index, self) => index === self.findIndex((t) => t.id === item.id) ) })
Filter and IndexOf
const groupedWithoutDuplicates = {} Object.entries(DATA).forEach(([key, value]) => { const ids = value.map((item) => item.id) groupedWithoutDuplicates[key] = value.filter((item, index) => index === ids.indexOf(item.id)) })
Lodash
const groupedWithoutDuplicates = {} Object.entries(DATA).forEach(([key, value]) => { groupedWithoutDuplicates[key] = _.uniqBy(value, 'id') })