Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniqWith vs Set
(version: 0)
Comparing performance of:
lodash vs set
Created:
2 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>
Tests:
lodash
const target = []; for (let i = 0; i < 10000; i++) { const newObj = { a: Math.floor(Math.random() * 10) } target.push(newObj) } return _.uniqWith(target, function(val, otherVal) { return val.a === otherVal.a })
set
const target = []; for (let i = 0; i < 10000; i++) { const newObj = { a: Math.floor(Math.random() * 10) } target.push(newObj) } const newArray = target.map((obj) => JSON.stringify(obj)); const newSet = new Set(newArray) return [...newSet].map((objString)=> JSON.parse(objString));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
set
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):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark test case hosted on MeasureThat.net. The benchmark compares the performance of two approaches: using `lodash` library's `uniqWith` function and using a built-in `Set` data structure. **Options Compared** 1. **Lodash**: A popular utility library for JavaScript that provides various functions, including `uniqWith`. 2. **Set**: A built-in JavaScript data structure used to store unique values. **Pros and Cons of Each Approach** ### Lodash (`uniqWith`) Pros: * Provides a concise and expressive way to remove duplicates from an array. * Often used in production code due to its popularity and maintainability. Cons: * Adds overhead due to the library's runtime dependencies and abstraction. * Can be slower compared to native JavaScript implementations, especially for large datasets. ### Set Pros: * Native implementation with zero overhead due to lack of runtime dependencies. * Efficient use of memory to store unique values. Cons: * Requires manual handling of JSON stringification and parsing (in this case). * May not be as concise or expressive as `uniqWith`. **Library Used** In the benchmark, the `lodash` library is used for its `uniqWith` function. This function takes a callback function as an argument, which allows you to specify how duplicates should be handled. ```javascript function(val, otherVal) { return val.a === otherVal.a } ``` This callback returns `true` if the values are equal, and `false` otherwise, allowing `uniqWith` to determine whether a value is a duplicate or not. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax used in this benchmark. However, it's worth noting that MeasureThat.net uses WebAssembly (WASM) for executing benchmarks, which provides a sandboxed environment for running JavaScript code.
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash - uniq
uniqBy performance lodash vs native
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?