Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object (real-world) Performance 2
(version: 0)
Lookup of map vs object (in a real-world test format)
Comparing performance of:
Conspicuous Map lookup vs Conspicuous Obj lookup vs Conspicuous Map lookup 2 vs Conspicuous Obj lookup 2
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var keyCount = 16384 var keys = [] var map = new Map() var obj = Object.create(null) // Hide lookup keys to prevent V8 cheating (AKA Optimizing) var getConspicuousKey = seed => keys[Math.floor(seed * keyCount)] // Setup out test objects w/ random values for (let i=0; i<keyCount; i++) { let val = Math.random() let key = Math.random() keys.push(key) map.set(key,val) obj[key] = val }
Tests:
Conspicuous Map lookup
for (let i=0; i<keyCount; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = map.get(key) }
Conspicuous Obj lookup
for (let i=0; i<keyCount; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = obj[key] }
Conspicuous Map lookup 2
for (let i=0; i<keyCount; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = map.get(key) }
Conspicuous Obj lookup 2
for (let i=0; i<keyCount; i++) { let seed = Math.random() let key = getConspicuousKey(seed) a = obj[key] }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Conspicuous Map lookup
Conspicuous Obj lookup
Conspicuous Map lookup 2
Conspicuous Obj lookup 2
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 the provided benchmark and its test cases. **Benchmark Overview** The benchmark measures the performance of JavaScript objects (`Map` and `Object`) when performing lookups on keys that are not directly accessible (i.e., "conspicuous" keys). The benchmark creates a large array of random keys, sets the same value for each key in both the `Map` and `Object`, and then performs lookups using these keys. **Options Compared** The benchmark compares two approaches: 1. **Map lookup**: Using the `get()` method to retrieve the value associated with a key in the `Map`. 2. **Object lookup**: Using the bracket notation (`obj[key]`) to retrieve the value associated with a key in the `Object`. **Pros and Cons of Each Approach** **Map Lookup:** Pros: * Faster, as it uses a hash table for lookups. * More efficient when working with large datasets. Cons: * May be slower if the keys are not uniformly distributed or if there are collisions. * May use more memory due to the overhead of storing the map. **Object Lookup:** Pros: * May be faster in some cases, as it avoids the overhead of a hash table. * More intuitive for developers familiar with bracket notation. Cons: * Slower than `Map` lookup due to the need to perform a string lookup and indexing. * Less efficient when working with large datasets. **Other Considerations** The benchmark also takes into account the use of "conspicuous" keys, which are generated using a seeded random number generator. This adds an additional layer of complexity, as the same key will be used across multiple iterations, potentially leading to biased results if not properly accounted for. **Library Used:** None is explicitly mentioned in the provided code. However, the `Map` object is part of the ECMAScript standard, and the `Object` object also comes from the ECMAScript standard. The `Math.random()` function used throughout the benchmark is a built-in JavaScript function. **Special JS Features/Syntax:** The benchmark uses several advanced JavaScript features, including: * Sealed object creation (`var obj = Object.create(null)`): This creates an object with no prototype chain. * Bracket notation (`obj[key]`): This is used for property access on objects. * Hash table implementation ( implicit ): The `Map` object uses a hash table internally to store key-value pairs. These features are not explicitly mentioned in the question, but they are essential to understanding the benchmark's behavior and performance characteristics.
Related benchmarks:
iterating from a filled object VS iterating from a map
Array from() vs Map.keys()
Object spread vs New map with string keys
array includes vs object key lookup, large arrays
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?