Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniq vs lodash vs set
(version: 0)
Comparing performance of:
set vs lodash vs uniq
Created:
one year 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:
set
var l = new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]); return l;
lodash
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(l);
uniq
function uniq(items) { const result = []; for (let i = 0; i < items.length; i++) { const item = items[i] if (result.includes(item)) continue; result.push(item) } return result; } var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return uniq(l);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
set
lodash
uniq
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
set
4225498.0 Ops/sec
lodash
6953493.0 Ops/sec
uniq
7933397.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark is comparing three approaches to remove duplicates from an array: `Set`, `Lodash` (`_.uniq`), and a custom implementation (`uniq`). The goal is to determine which approach is the fastest. **What's being tested?** * `Set`: A built-in JavaScript object that stores unique values. When you try to add a duplicate value, it simply ignores it. * `Lodash` (`_.uniq`): A popular JavaScript library that provides various utility functions. The `_uniq` function takes an array as input and returns a new array with duplicates removed. * Custom implementation (`uniq`): A simple recursive function that checks for duplicates in the input array. **Options Compared** The benchmark is comparing three options: 1. `Set`: Using the built-in JavaScript object to remove duplicates. 2. `Lodash` (`_.uniq`): Leveraging a popular JavaScript library for duplicate removal. 3. Custom implementation (`uniq`): Implementing a custom solution using a simple recursive function. **Pros and Cons of Each Approach** * **Set**: Pros: Efficient, easy to use, and built-in to JavaScript. Cons: Not designed specifically for array processing, may not be suitable for large datasets or complex data structures. * **Lodash` (`_.uniq`): Pros: Well-maintained library with a wide range of utility functions, highly optimized for performance. Cons: Requires an additional import and introduces external dependencies, which might be overhead for some users. * **Custom implementation (`uniq`)**: Pros: Lightweight, easy to understand, and doesn't require any additional imports or libraries. Cons: May not be as efficient as the other two options, especially for large datasets. **Library Used** The benchmark uses `Lodash`, version 4.17.10, which is a popular JavaScript library providing various utility functions. **Special JS Features/Syntax** None are explicitly mentioned in the provided JSON data. However, if you're interested in exploring more advanced JavaScript features or syntax, you can explore other benchmarks on MeasureThat.net that might cover those topics. **Alternatives** If you'd like to explore alternative approaches for removing duplicates from an array, consider these options: 1. Using `Array.prototype.filter()` and a callback function: This approach iterates over the array, checking each element against every other element. 2. Using `Array.prototype.reduce()`: This approach accumulates a new array with unique elements by applying a reduce operation to the original array. 3. Utilizing modern JavaScript features like `Map` or `Set` for more efficient data structures. For a deeper dive into these alternatives, you can search for more benchmark results on MeasureThat.net or explore online resources and documentation for each of these approaches. If you have any further questions about this benchmark or would like to explore other JavaScript benchmarks, feel free to ask.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
Lodash - uniq
Lodash uniqBy vs Javascript uniqBy
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?