Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
lodash uniqby
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/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Lodash
2021.7 Ops/sec
JS using filter
1606.0 Ops/sec
JS using reduce
1113.5 Ops/sec
HTML Preparation code:
<script src="lodash.js"></script>
Script Preparation code:
const array1 = [...Array(10000).keys()].map(key => ({ id: key, value: 'array1' })); const array2 = [...Array(10000).keys()].map(key => ({ id: key, value: 'array2' })); const combineArray = [...array1, ...array2]
Tests:
Lodash
_.uniqBy(combineArray,'id')
JS using filter
const uniqBy = (array, key) => { const seen = new Set() return array.filter(item => { const keyValue = item[key] if (seen.has(keyValue)) { return false } else { seen.add(keyValue) return true } }) } uniqBy(combineArray,'id')
JS using reduce
const uniqBy = (array,key) => { const _key = key ?? 'id' return Object.values( array.reduce((acc, doc) => { if (!(doc[_key] in acc)) { acc[doc[_key]] = doc } return acc }, Object.create(null)), ) } uniqBy(combineArray,'id')