<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
var l = [ (new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]))];
return l;
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7];
return _.uniq(l);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Set | |
Array |
Test name | Executions per second |
---|---|
Set | 1975152.6 Ops/sec |
Array | 3986109.0 Ops/sec |
Let's break down what's being tested in this JavaScript microbenchmark.
Benchmark Overview
The benchmark compares the performance of two approaches to remove duplicate elements from an array: using a Set
object and using the _.uniq()
function from the Lodash library.
Options Compared
uniq()
function, which is designed to efficiently remove duplicates from an array while preserving the original order.Pros and Cons of Each Approach
Library: Lodash
Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, such as array manipulation, string formatting, and more. The _.uniq()
function in particular is designed to efficiently remove duplicates from an array while preserving the original order.
Other Considerations
In summary, this benchmark compares two common approaches for removing duplicates from an array: using a plain JavaScript array and an external library's _.uniq()
function. The Lodash approach is optimized for performance but requires including an external library, while the Array method is lightweight but may not be as efficient for large datasets.