Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Remove duplicate: Pure JS VS Lodash
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
Pure JS: map
885628.6 Ops/sec
Pure JS: forEach
1108264.6 Ops/sec
Lodash: uniqBy
2463656.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:
var arr = [ { id: 123, name: "abc", }, { id: 1234, name: "abcd", }, { id: 123, name: "abc", }, { id: 4321, name: 'dcba', }, ]; var key='id';
Tests:
Pure JS: map
var indexArray = []; var newArray = arr.map(a => { if (indexArray.indexOf(a[key]) < 0) { indexArray.push(a[key]); return a; }; return -1; }).filter(a => a != -1);
Pure JS: forEach
var indexArray = []; var newArray = []; arr.forEach(a => { if (indexArray.indexOf(a[key]) < 0) { indexArray.push(a[key]); newArray.push(a); }});
Lodash: uniqBy
var newArray = _.uniqBy(arr, key);