Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Hashmap vs Dictionary object vs lodash uniqWith
(version: 0)
Comparing performance of: Hashmap, Dictionary and lodash uniqWith.
Comparing performance of:
Hashmap vs Dictionary object vs _uniqWith
Created:
4 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>
Script Preparation code:
var valueList2 = ["apa", "anya", "gyerek"]; for (var i = 0; i < 14200; i++) { valueList2.push("Apa" + i); }
Tests:
Hashmap
var res2 = new Map(); for (var value of valueList2) { if (!res2.get(value.toLowerCase())) { res2.set(value.toLocaleLowerCase(), value.toLocaleLowerCase()); } }
Dictionary object
var dictionary = {}; for (var i = 0; i < valueList2.length; i++) { var item = valueList2[i].toLowerCase(); if (!dictionary[item]) { dictionary[item] = i; } }
_uniqWith
_.uniqWith(valueList2, (arrVal, othVal) => arrVal.toLowerCase() === othVal.toLowerCase());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Hashmap
Dictionary object
_uniqWith
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/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Hashmap
785.6 Ops/sec
Dictionary object
679.7 Ops/sec
_uniqWith
1.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is tested?** The benchmark compares the performance of three data structures: 1. **Hashmap**: A built-in JavaScript data structure that stores key-value pairs in an unordered collection. 2. **Dictionary object**: An object with key-value pairs, similar to a hashmap but not implemented as a native JavaScript data structure (in this case, it's a custom implementation). 3. **lodash uniqWith**: A function from the popular JavaScript library Lodash that removes duplicate elements from an array based on a provided comparison function. **Options compared** The benchmark compares the performance of these three approaches: * Hashmap: Using the native `Map` data structure in JavaScript. * Dictionary object: Creating and using a custom object with key-value pairs. * lodash uniqWith: Using the Lodash library's `uniqWith` function to remove duplicates from an array. **Pros and Cons** Here are some pros and cons of each approach: 1. **Hashmap**: * Pros: + Native JavaScript data structure, optimized for performance. + Easy to use and understand. * Cons: + Limited control over implementation details (e.g., caching, hashing). 2. **Dictionary object**: * Pros: + Customizable implementation (e.g., cache size, collision resolution). + More control over data structure properties. * Cons: + Requires more code and setup than using a native data structure. 3. **lodash uniqWith**: * Pros: + Easy to use and understand (no custom implementation required). + Provides a reliable and efficient way to remove duplicates. * Cons: + External dependency on the Lodash library. + May have performance overhead due to function call and array manipulation. **Library usage** The benchmark uses **lodash uniqWith**, which is a utility function from the popular JavaScript library Lodash. The `uniqWith` function takes two arguments: an array of values and a comparison function that determines whether elements should be considered duplicates. In this case, the comparison function simply checks if the lowercase version of each value is equal. **Special JS features** This benchmark does not use any special JavaScript features or syntax, such as async/await, Promises, or ES modules. **Other alternatives** If you were to implement a custom hashmap-like data structure from scratch, here are some alternative approaches: 1. **Arrays and Object**: Use two separate arrays (one for keys and one for values) and an object to store the key-value pairs. 2. **Trie data structure**: Implement a Trie (prefix tree) data structure to efficiently store and retrieve key-value pairs. 3. **Synchronized hash table**: Create a synchronized hash table using a lock or mutex to ensure thread safety. Keep in mind that these alternatives would require more code and expertise than using a native JavaScript data structure like `Map`.
Related benchmarks:
lodash uniq vs native uniq
Lodash Map&Uniq vs Javascript dictionary
uniqBy vs stringify performance
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq
lodash uniq vs set spread
Comments
Confirm delete:
Do you really want to delete benchmark?