Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Unique Array: Lodash or from Set
(version: 0)
Comparing performance of:
Array from Set vs Lodash Uniq
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var testArr = "JRQ, SCTS, KKC, KKC, KKC, RGC, PDA, PDA, RGC, KKC, PDA, PDA, PDA, SCTS, KKC, DAH, JRM, JRM, RGC, RGC, DAMB, DAMB, KKC, SCTS, RGC, PAC, KKC, KKC, SCTS, SCTS, SCTS, SCTS, KKC, KKC, MIDK, MIDK, KKC, RGC, CHTS, CHTS, CHTS, CHTS, JRQ, JRQ, SCTS, DAH, DAH, AEWC, DQQL, PAC, DQQL, DQQL, AEWC, KIS, AEWC, DQQL, AEWC, PAC, RHN, RHN, KIS, KIS, RHN, RHN, RHN, KIS, KIS, KIS, KIS, KIS, JRQ, RGC, SCTS, RGC, SCTS, KKC, SCTS, SCTS, SCTS, SCTS, SCTS, SCTS, SCTS, SCTS, SCTS, SCTS, DGJ, DGJ, RGC, KKC, KKC, MIDK, MIDK, RGC, KKC, RGC, RGC, RGC, RGC, DGJ, DGJ, PDA, RGC, JRQ, PDA, SCTS, RGC, RGC, SCTS, DXJM, JRQ, PDA, PDA, PDA, SCTS, DAH, DAH, RGC, RGC,".split(', ');
Tests:
Array from Set
Array.from( new Set( testArr ) )
Lodash Uniq
_.uniq(testArr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array from Set
Lodash Uniq
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!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
The provided benchmark measures the performance of two different approaches to convert an array into a set and back into an array. **Approach 1: Using Array.from() and Set()** This approach uses the built-in `Set` object in JavaScript to create a set from the array, and then converts it back into an array using the `Array.from()` method. This is a straightforward and efficient way to achieve this conversion. **Approach 2: Using Lodash's uniq() function** This approach uses the `uniq` function from the Lodash library, which is a popular utility library for JavaScript. The `uniq` function takes an array as input and returns a new array with duplicate elements removed. This approach requires loading the Lodash library in the test environment. **Pros and Cons of each approach:** 1. **Array.from() and Set():** * Pros: + Fast and efficient, since it uses built-in JavaScript objects. + No additional dependencies required (other than the browser itself). * Cons: + May not work as expected in older browsers that don't support `Set`. 2. **Lodash's uniq():** * Pros: + Robust and reliable, since it's a widely-used library with extensive testing. + Works across various browsers, including older ones. * Cons: + Requires loading an additional library (Lodash), which can add overhead. + May be slower than the native `Set`-based approach. **Library usage:** In this benchmark, Lodash is used to provide the `uniq` function. The Lodash library provides a range of utility functions for tasks such as data manipulation, string manipulation, and more. **Special JS feature or syntax:** None of the approaches in this benchmark rely on any special JavaScript features or syntax. However, it's worth noting that the use of `Set` objects is a relatively modern feature in JavaScript, introduced with ECMAScript 2015 (ES6). **Alternatives:** Other alternatives for converting an array into a set and back into an array might include: 1. Using a library like `collections` or `arrays` from other utility libraries (e.g., Ramda, Immutable.js). 2. Implementing the conversion manually using loops and conditional statements. 3. Using other built-in JavaScript objects, such as `Map`, to create a set-like data structure. However, these alternatives may not be as efficient or reliable as the native `Set`-based approach, especially when it comes to performance and browser compatibility.
Related benchmarks:
Unique Array: Lodash or from Set with Clean and Sort
Unique Array: Lodash or spread new Set
lodash vs un
Unique Array: Lodash vs spread new Set vs reduce vs for v2
Comments
Confirm delete:
Do you really want to delete benchmark?