Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object (index + prop)
(version: 0)
Lookup of map vs object
Comparing performance of:
Map lookup vs Obj lookup vs Obj lookup property
Created:
3 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 = 1000, 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']; }
Obj lookup property
for (i = 0; i < count; i++) { a = obj.a; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Map lookup
Obj lookup
Obj lookup property
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):
Let's break down what's being tested in the provided JSON. **Benchmark Definition** The benchmark measures the performance difference between three approaches: 1. **Object lookup using bracket notation (`obj['a']`)**: This is compared to... 2. **Map lookup using the `get()` method (`map.get('a')`)**: ...and to... 3. **Map lookup directly accessing the property on the map object (`a = map['a']`)** These three approaches are tested in a loop, where the value of 'a' is retrieved 1000 times. **Pros and Cons** * **Object Lookup (Bracket Notation)**: + Pros: Widely supported, easy to read, and write. + Cons: May be slower than direct property access or map lookup due to string comparison. * **Map Lookup (`map.get('a')`)**: + Pros: Fast, efficient, and suitable for large datasets. Maps are optimized for key-value pairs. + Cons: Requires a Map object creation upfront, which might incur additional overhead. * **Direct Property Access (Map Object)**: + Pros: Directly accessing the property without any extra lookup or creation overhead. + Cons: Not supported in older browsers or environments, as it relies on object literal syntax. **Library and Special JS Feature** There is no explicit library used in this benchmark. However, using a Map object is a JavaScript feature that's been part of the language since ECMAScript 2015 (ES6). **Other Considerations** * **Cache Performance**: The benchmark might not accurately reflect real-world cache performance, as it doesn't simulate caching mechanisms or variable lookup complexities. * **Browser and OS Variability**: The results provided are specific to Chrome on Windows. Other browsers, operating systems, or hardware configurations may yield different performance characteristics. **Alternative Benchmarks** Other benchmarks that measure similar performance differences could include: * String comparison vs. regular expression matching * DOM element lookup using `document.querySelector()` vs. direct property access vs. CSS selectors * Array indexing performance compared to object property access Keep in mind that the choice of benchmark depends on your specific use case and requirements, as well as the environment and constraints you're working with.
Related benchmarks:
Array from() vs Map.keys()
Array from() vs Map.keys() vs Map.values() vs spread
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?