<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
var arr = [ 18, 2, 1, 13, 12, 7, 6, 0, 8, 15, 7, 9, 9, 18, 3, 18, 3, 9, 3, 8, 7, 12, 7, 14, 4, 19, 10, 5, 2, 19, 1, 14, 19, 18, 7, 12, 10, 2, 4, 11, 9, 4, 12, 2, 18, 6, 7, 10, 9, 3, 11, 9, 2, 12, 15, 0, 14, 3, 5, 18, 16, 16, 9, 15, 5, 9, 16, 6, 13, 4, 19, 5, 11, 18, 18, 6, 19, 5, 4, 2, 3, 4, 11, 9, 16, 17, 10, 15, 14, 7, 11, 0, 5, 13, 7, 14, 13, 16, 9, 19, 4, 0, 4, 0, 5, 2, 15, 15, 13, 10, 3, 8, 18, 7, 10, 4, 4, 16, 14, 1, 4, 19, 1, 14, 15, 16, 5, 4, 0, 0, 12, 0, 4, 7, 0, 4, 1, 9, 14, 12, 12, 1, 2, 6, 0, 10, 6, 19, 12, 4, 7, 11, 13, 2, 1, 19, 9, 6, 15, 9, 2, 11, 14, 5, 18, 13, 16, 19, 8, 12, 12, 4, 5, 1, 10, 19, 0, 2, 6, 19, 4, 19, 7, 18, 18, 5, 16, 18, 13, 8, 9, 4, 14, 12, 10, 10, 19, 11, 8, 9, 13, 6, 0, 10, 6, 6, 5, 8, 3, 18, 11, 12, 3, 14, 12, 8, 7, 12, 6, 4, 4, 2, 19, 17, 14, 11, 2, 16, 13, 10, 19, 9, 18, 12, 9, 16, 6, 14, 13, 15, 2, 15, 19, 9, 19, 0, 5, 11, 0, 15, 17, 0, 9, 18, 0, 15, 11, 4, 3, 9, 2, 18, 18, 6, 19, 11, 3, 0, 7, 5, 9, 3, 11, 18, 0, 10, 1, 8, 1, 18, 7, 3, 0, 13, 11, 7, 10, 5, 19, 11, 4, 4, 0, 18, 9, 3, 3, 19, 9, 4, 16, 13, 13, 14, 18, 12, 17, 2, 12, 1, 13, 12, 11, 8, 18, 14, 5, 18, 0, 3, 5, 17, 3, 16, 3, 11, 16, 19, 13, 11, 2, 15, 6, 12, 0, 13, 2, 2, 16, 17, 10, 18, 3, 18, 5, 18, 3, 8, 0, 4, 13, 9, 18, 7, 15, 12, 3, 11, 3, 8, 12, 6, 10, 3, 2, 18, 3, 19, 10, 19, 13, 19, 15, 2, 14, 18, 15, 10, 18, 19, 7, 10, 3, 16, 7, 7, 8, 19, 1, 15, 9, 18, 18, 5, 14, 11, 11, 14, 5, 2]
var u = new Set(arr);
return u;
var u = _.uniq(arr)
return u;
var u = arr.filter((v, i, a) => a.indexOf(v) === i)
return u;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Set | |
uniq | |
filter |
Test name | Executions per second |
---|---|
Set | 112609.9 Ops/sec |
uniq | 113232.3 Ops/sec |
filter | 130057.5 Ops/sec |
Overview
MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks, comparing the performance of different approaches. The provided benchmark definition JSON and individual test cases describe three scenarios: using a Set data structure, Lodash's uniq
function, and Array filtering.
Benchmark Definition
The benchmark definition JSON describes a scenario where an array is created with 50 elements, and then:
var u = new Set(arr); return u;
)._.uniq(arr)
.var u = arr.filter((v, i, a) => a.indexOf(v) === i); return u;
).Individual Test Cases
Each individual test case describes a specific benchmark definition:
uniq
function to remove duplicates from the input array and returns the result.Latest Benchmark Result
The latest benchmark result shows the performance metrics for each test case:
Comparison
Based on the latest benchmark result, the Array filtering method outperforms both the Set data structure and Lodash's uniq
function by a significant margin (over 10 times). This suggests that the filtering approach is more efficient in this specific scenario.
However, it's essential to note that these results may vary depending on the specific use case, array size, and browser environment. MeasureThat.net provides a useful platform for comparing different approaches and identifying optimal solutions for specific problems.