Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs native uniq
(version: 0)
Comparing performance of:
native uniq vs ld uniq
Created:
6 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 obj = [1, 2, 3, 4, 6, 6, 4, 1, 2, 2, 3];
Tests:
native uniq
let u = new Set(obj);
ld uniq
let u = _.uniq(obj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native uniq
ld uniq
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native uniq
11852571.0 Ops/sec
ld uniq
25669662.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the provided benchmark and its options. **What is tested on the provided JSON?** The JSON represents a JavaScript microbenchmark that compares the performance of two approaches: using the native `Set` data structure (also known as "native uniq") and using the `_uniq` function from the Lodash library. The test case generates an array of duplicate values (`obj`) and measures how many unique elements can be extracted from it using both methods. **Options compared** There are two options being compared: 1. **Native uniq**: This approach uses the native `Set` data structure to extract unique elements from the input array. A `Set` is a collection of unique values that cannot have duplicate entries. 2. **Lodash uniq**: This approach uses the `_uniq` function from the Lodash library to extract unique elements from the input array. **Pros and Cons** **Native uniq:** Pros: * Native implementation, so it's likely to be highly optimized for performance. * No additional library dependencies required. Cons: * May not support all types of data (e.g., non-numeric values). * Can be slower than a specialized library implementation if the input size is large. **Lodash uniq:** Pros: * Supports all types of data (e.g., non-numeric values). * Often faster than native implementations for large input sizes. * Provides additional features, such as preserving order or handling null/undefined values. Cons: * Requires an external library dependency. * May have overhead due to the library's initialization and loading processes. **Other considerations** The benchmark also considers other factors, such as: * **DevicePlatform** and **OperatingSystem**: These are reported by the browser during execution and can affect performance. The benchmark assumes a Desktop platform on Windows. * **ExecutionsPerSecond**: This measures how many unique elements can be extracted from the input array per second. **Library and syntax** In this case, the Lodash library is used to implement the `_uniq` function. The `Set` data structure is a native JavaScript implementation that's used as an alternative for comparison. There are no special JavaScript features or syntaxes being tested in this benchmark. **Alternatives** Other alternatives to compare unique elements could include: * Using a different library, such as jQuery's `unique()` function. * Implementing the uniqueness test using only basic arithmetic operations (e.g., iterating through the array and keeping track of unique values). * Using a more specialized data structure, like a Bloom filter or a trie. However, these alternatives may not provide comparable performance to the native implementation or Lodash implementation, which are optimized for specific use cases.
Related benchmarks:
Lodash uniq vs Set to unique array
lodash uniqBy vs custom uniqBy
lodash uniq vs native uniqoififie3f02i409rfi23k
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?