Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniqby
(version: 4)
Comparing performance of:
Lodash vs JS using filter vs JS using reduce
Created:
one year ago
by:
Registered User
Jump to the latest result
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')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
JS using filter
JS using reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
3887.2 Ops/sec
JS using filter
3491.4 Ops/sec
JS using reduce
1985.2 Ops/sec
Related benchmarks:
Lodash Uniq vs Javascript Set2
Lodash Uniq vs Javascript Set 222
lodash uniq vs vanilla set
Lodash Uniq vs Javascript Set 2
Lodash Uniq vs Javascript Set 123
Javascript Set vs Lodash Uniq
Lodash Uniq vs Javascript Set II
Lodash Uniq vs Javascript Set 10000 items
remove duplicate
Comments
Confirm delete:
Do you really want to delete benchmark?