Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Unique Array: Lodash vs spread new Set vs reduce vs for - random data
(version: 0)
Comparing performance of:
Array Unique vs For Loop vs Array from Set vs Lodash Uniq
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var testArr = []; for (var i = 0; i < 100000; i++) { testArr.push(String(getRandomInt(1000))); }
Tests:
Array Unique
const { resultArray } = testArr.reduce((result, item) => { if(!result.resultMap[item]){ result.resultMap[item] = true; result.resultArray.push(item) } return result; }, {resultArray: [], resultMap: {}}); return resultArray;
For Loop
const resultArray = []; const resultMap = {}; for(let item of testArr) { if(!resultMap[item]){ resultMap[item] = true; resultArray.push(item) } } return resultArray;
Array from Set
[...new Set(testArr)]
Lodash Uniq
_.uniq(testArr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array Unique
For Loop
Array from Set
Lodash Uniq
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Labels
Unique lodash vs vanilla
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 4
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?