Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs Map2
(version: 0)
Comparing performance of:
Map vs use lodash
Created:
5 years 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:
Map
const arr = [{id: 1}, {id: 2}, {id: 3}, {id: 1}, {id: 2}, {id: 3}, {id: 1}, {id: 2}, {id: 3}]; const uniqs = []; const map = new Map(); for (const item of arr) { if (!map.has(item.id)) { map.set(item.id, item.id); uniqs.push(item); } } return uniqs;
use lodash
var l = [{id: 1}, {id: 2}, {id: 3}, {id: 1}, {id: 2}, {id: 3}, {id: 1}, {id: 2}, {id: 3}]; return _.uniq(l, 'id');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map
use lodash
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):
**What is being tested?** The benchmark tests the performance of two approaches to remove duplicates from an array of objects: 1. **Using a `Map` data structure**: The test creates an array of objects with duplicate IDs, then iterates through the array using a `for...of` loop and adds each object to the map if its ID is not already present in the map. It then returns an array containing only the unique objects from the original array. 2. **Using the Lodash library**: The test uses the Lodash library's `uniq` function to remove duplicates from the same array of objects with duplicate IDs. **Options compared** The two options being compared are: * Using a `Map` data structure * Using the Lodash library **Pros and Cons of each approach:** * **Using a `Map` data structure:** + Pros: - Can be more efficient for large datasets, as it uses a hash table to store unique IDs. - Does not require any external dependencies (no Lodash). - Cons: - May have slower performance on smaller datasets due to the overhead of creating and iterating over the map. * **Using the Lodash library:** + Pros: - Often provides optimized implementations for common data structures like arrays. - Can be more convenient for developers who are already familiar with the library's API. - Cons: - Requires an external dependency, which can add overhead and complexity to the benchmark. **Library used** In this benchmark, Lodash is used as a third-party library. The `uniq` function is a part of Lodash's utility functions, which provides a simple and efficient way to remove duplicates from arrays. **Special JS feature or syntax not mentioned** There are no special JavaScript features or syntaxes being tested in this benchmark.
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash uniqBy vs Map destructuring
uniqBy performance lodash vs native
uniqBy performance and map
Comments
Confirm delete:
Do you really want to delete benchmark?