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 Filter
(version: 1)
Comparing performance of:
Spread vs use lodash vs Array.from vs .filter() and .indexOf()
Created:
9 months 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>
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]) );
.filter() and .indexOf()
const arr = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7] return arr.filter((item, index) => arr.indexOf(item) === index)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Spread
use lodash
Array.from
.filter() and .indexOf()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Spread
9262730.0 Ops/sec
use lodash
25500942.0 Ops/sec
Array.from
9272677.0 Ops/sec
.filter() and .indexOf()
1207668.5 Ops/sec
Related benchmarks:
lodash uniq vs Array.from(new Set()) vs spread new Set()
lodash uniq vs Array.from(new Set()) vs spread new Set() vs array.filter
lodash uniq vs set + spread
Lodash uniq vs Set to unique array
lodash uniq vs Array.from(new Set()) vs spread new Set() with filter
lodash uniq vs set array comprehension
lodash uniq vs spread new Set()
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized
Comments
Confirm delete:
Do you really want to delete benchmark?