Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 2
(version: 0)
Comparing performance of:
Spread vs use lodash vs Array.from vs For vs For memory optimized
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Script Preparation code:
let array = []; for (let i = 0; i < 100000; i++) {array.push(~~(Math.random() * 2000))}
Tests:
Spread
return [...new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7])]
use lodash
return _.uniq([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]);
Array.from
return Array.from( new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]) );
For
const visited = {}; const uniques = []; const initial = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; for(let i=0;i<initial.lenght;i++){ if(!visited[initial[i]]) { visited[initial[i]] = true; uniques.push(initial[i]); } } return uniques
For memory optimized
const visited = {}; const uniques = []; const initial = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; for(let i=0;i<initial.lenght;i++){ if(!(initial[i] in visited)) { visited[initial[i]] = undefined; uniques.push(initial[i]); } } return uniques
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Spread
use lodash
Array.from
For
For memory optimized
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!
Comments
Confirm delete:
Do you really want to delete benchmark?