Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
testqwertyuiop
(version: 0)
Comparing performance of:
Conspicuous Map lookup vs Conspicuous Obj lookup
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var keyCount = 16384 var keys = [] var map = new Map() var obj = {} // 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 val = Math.random() let key = Math.random() map.set(key,val) }
Conspicuous Obj lookup
for (let i=0; i<keyCount; i++) { let val = Math.random() let key = Math.random() obj[key] = val }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Conspicuous Map lookup
Conspicuous 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
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and other considerations. **Benchmark Definition** The provided `Script Preparation Code` is used to prepare the test environment for the benchmark. It creates: 1. An array of 16,384 random keys (`keys`) and a Map (`map`) with those keys as indices. 2. An object (`obj`) with the same keys as the map. 3. A function (`getConspicuousKey`) that returns a random key from the `keys` array. The purpose of this setup is to create a scenario where the benchmark can measure the performance of looking up values in both the Map and object data structures. **Options Compared** Two options are compared: 1. **Map lookup**: The `Benchmark Definition` uses a simple loop that iterates over the keys, looks up the corresponding value in the `map`, and assigns it to an empty variable. 2. **Object lookup**: The second `Benchmark Definition` is similar to the first one, but instead of using the `map` object, it directly accesses the `obj` object using the random key as an index. **Pros and Cons** * **Map Lookup**: + Pros: Maps are designed for efficient key-value lookups, making this operation relatively fast. + Cons: In this specific benchmark, the Map's internal implementation might not be optimized for sequential lookups, potentially leading to slower performance compared to object lookups. * **Object Lookup**: + Pros: Objects are designed for fast property access, and in this case, using a random key as an index can lead to faster lookup times compared to using a Map. + Cons: This approach relies on the object's internal implementation and caching mechanisms, which might not always optimize performance. **Library Usage** There is no explicit library usage mentioned in the `Script Preparation Code`. However, it's worth noting that modern JavaScript engines like V8 (used by Chrome) have optimized internal data structures for efficient lookups. The use of a Map and object with random keys is likely intended to bypass some of these optimizations and measure the performance under various conditions. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark, aside from the `let` and `const` keywords, which are part of the ECMAScript standard. **Alternatives** If you wanted to run this benchmark with different options, you could try: * Using a different data structure, such as an array or a Set, for the lookups. * Adding more complexity to the lookup operations, such as using a recursive function or involving more properties of the object. * Measuring performance on different browsers, platforms, or devices. Keep in mind that modifying the benchmark's setup and test cases might require significant changes to the `Script Preparation Code` and could lead to less representative results.
Related benchmarks:
Map vs Object (real-world) Performance (lookup and set)
Map vs Object (real-world) Performance (disabling object-specific optimizations and default keys)
Map vs Object (real-world) Performance (better)
Map vs Object (real-world) Performance (better) 2
Map vs Object (real-world) Performance (non-numeric key)
Comments
Confirm delete:
Do you really want to delete benchmark?