Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
uniqBy performance lodash vs native
lodash vs javascript
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
lodash
2644508.8 Ops/sec
javascript
2824100.5 Ops/sec
native
3010491.2 Ops/sec
HTML Preparation code:
<script>https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.js</script>
Script Preparation code:
var data = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}, {a: 7}, {a: 8}, {a: 1}];
Tests:
lodash
_.uniqBy(data, 'a');
javascript
const sortBy = (key) => { return (a, b) => (a[key] > b[key]) ? 1 : (b[key] > a[key] ? -1 : 0); }; const uniqBy = (arr, a) => { arr.sort(sortBy(a)); const arr1 = []; arr1.push(arr[0]); for (let index = 1; index < arr.length; index++) { if (arr[index-1] && arr[index -1].a !== arr[index].a) { arr1.push(arr[index]); } } return arr1; } uniqBy(data, 'a')
native
function uniqueBy(arr, prop){ const record = [] const seen = {} for (let i = 0, len = arr.length; i < len; ++i) { // Notice the len = arr.length const item = arr[i] const val = item[prop] if (!seen[val]) { seen[val] = 1 record.push(item) } } } uniqueBy(data, 'a')