Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Unique Array: Lodash or from Set with Clean and Sort
(version: 0)
Comparing performance of:
Lodash vs Native vs Native Spread
Created:
5 years ago
by:
Registered User
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:
Lodash
_.chain( testArr ).uniq().compact().sort().value()
Native
Array.from(new Set( testArr.filter( Boolean ).sort() ) )
Native Spread
[...new Set( testArr.filter( Boolean ).sort()) ]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Native
Native Spread
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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
277369.6 Ops/sec
Native
137347.1 Ops/sec
Native Spread
136995.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Definition:** The benchmark is designed to test how quickly an array can be processed from raw string data using two different approaches: 1. **Lodash**: Using the Lodash library to chain methods (`_.chain`, `uniq`, `compact`, `sort`, `value`) on the input array. 2. **Native**: Using native JavaScript functions (`Array.from`, `new Set`, `filter`, `Boolean`, `sort`) without any external libraries. **Options Comparison:** The two options are: 1. **Lodash**: Pros: * Simplifies code and makes it easier to read * Provides a concise way to perform complex operations on arrays Cons: * Requires an external library, which may add overhead due to downloading and parsing 2. **Native**: Pros: * No additional overhead due to external libraries * Can be faster since native functions are optimized by the browser Cons: * Code becomes more verbose and harder to read * More error-prone due to lack of concise syntax **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object iteration, and function composition. In this benchmark, Lodash is used to chain methods on the input array to achieve the desired result. Pros: * Provides concise and expressive syntax * Easy to read and maintain Cons: * Requires an external library, which may add overhead * May not be suitable for all use cases or projects **Native JavaScript Functions** The native functions used in this benchmark are: 1. `Array.from`: Creates a new array from an iterable (in this case, the set created by filtering and sorting the input array). 2. `new Set`: Creates a new set from an iterable (in this case, the filtered and sorted input array). 3. `filter` and `Boolean`: Filters out falsy values from the input array. 4. `sort`: Sorts the remaining elements of the input array. Pros: * No additional overhead due to external libraries * Can be faster since native functions are optimized by the browser Cons: * Code becomes more verbose and harder to read * More error-prone due to lack of concise syntax **Other Alternatives** If you're looking for alternative approaches, consider the following: 1. **Using `reduce()`**: Instead of chaining methods or using `Array.from` and `new Set`, you can use `reduce()` to iterate over the array and build the result. 2. **Using a custom implementation**: If performance is critical, you might consider implementing your own algorithm for processing arrays from raw string data. **Test Case Explanation** The test cases are: 1. **Lodash**: Uses Lodash's `chain` function to chain methods on the input array, resulting in the desired output. 2. **Native**: Uses native JavaScript functions to process the input array, filtering out falsy values and sorting the remaining elements to produce the final result. Both approaches should produce the same output, but with different syntax and potential performance characteristics.
Related benchmarks:
Unique Array: Lodash or from Set
Unique Array: Lodash or spread new Set
Unique Array: Lodash vs spread new Set vs reduce vs for v2
lodash uniq vs set vs uniqSort
Comments
Confirm delete:
Do you really want to delete benchmark?