Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object 10k iterations
(version: 0)
Lookup of map vs object
Comparing performance of:
Map lookup vs Obj lookup
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; map.set('a', 5); obj['a'] = 5; var i = 0, count = 10000, a;
Tests:
Map lookup
for (i = 0; i < count; i++) { a = map.get('a'); }
Obj lookup
for (i = 0; i < count; i++) { a = obj['a']; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map lookup
Obj lookup
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
gemma2:9b
, generated one year ago):
This benchmark compares the performance of accessing values from JavaScript Maps versus traditional objects. Here's a breakdown: **Options Compared:** * **`map.get('a')`:** Uses the `.get()` method on a `Map` object to retrieve the value associated with the key 'a'. Maps are designed for efficient key-value storage and retrieval, especially when dealing with large datasets or unique keys. * **`obj['a']`:** Accesses the value associated with the key 'a' using bracket notation on a standard JavaScript object. Objects use a dictionary-like structure where keys can be strings, numbers, or symbols. **Pros and Cons:** | Approach | Pros | Cons | |----------|----------------------------------------------|-----------------------------------------------| | **Map** | - Efficient for large datasets. | - Slightly more complex syntax initially. | | **Object**| - Familiar syntax for most JavaScript developers. | - Can be slower than Maps, especially with large datasets. | **Other Considerations:** * **Key Type:** Maps support any data type as a key (strings, numbers, objects, etc.), while objects typically use strings as keys. * **Iteration:** Maps offer methods like `.keys()`, `.values()`, and `.entries()` for efficient iteration over their elements, which can be advantageous in certain scenarios. **Alternatives:** While this benchmark focuses on basic lookup performance, other data structures might be more suitable depending on the use case: * **Arrays:** Efficient for ordered sequences of values and accessing elements by index. * **Sets:** Store unique values and offer efficient membership testing. Let me know if you have any further questions!
Related benchmarks:
iterating from a filled object VS iterating from a map
Array from() vs Map.keys()
array includes vs object key lookup, large arrays
Map vs Object read performance for a 1000 key lookup
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?