Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Long int keys (19 digits)
(version: 0)
Based on https://www.measurethat.net/Benchmarks/Show/11290/4/map-vs-object-real-world-performance but with long int keys
Comparing performance of:
Conspicuous Map lookup vs Conspicuous Obj lookup vs Conspicuous Map lookup 2 vs Conspicuous Obj lookup 2
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var keyCount = 65535 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 = 3000000000000000000+((4000000000000000000*Math.random())|0) 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 what's being tested in this benchmark. **Benchmark Overview** The benchmark tests the performance of two data structures: `Map` and `Object`. Both data structures are used to store key-value pairs, but they have different underlying implementation details that affect their performance. **Key Features and Libraries Used** * The benchmark uses a custom `getConspicuousKey` function to generate keys for both the `Map` and `Object` data structures. This function is designed to make it difficult for the V8 JavaScript engine to optimize away the memory accesses, which helps prevent "cheating" by optimizing the test. * Both data structures use random values as keys and store corresponding values. **Options Being Compared** The benchmark compares the performance of two approaches: 1. **Conspicuous Map lookup**: This approach uses a `Map` data structure to store key-value pairs, where the key is generated using the `getConspicuousKey` function. 2. **Conspicuous Object lookup**: This approach uses an `Object` data structure to store key-value pairs, where the key is also generated using the `getConspicuousKey` function. **Pros and Cons of Each Approach** * **Conspicuous Map Lookup**: + Pros: Maps are optimized for fast lookups, which can lead to better performance. + Cons: The use of a custom `getConspicuousKey` function may still allow the V8 engine to optimize away the memory accesses if it's deemed unnecessary. * **Conspicuous Object Lookup**: + Pros: Objects are also optimized for fast lookups, but the use of a custom key generation function can help prevent optimization. + Cons: The lookup performance may be lower due to the need to access the property on an object. **Other Considerations** The benchmark uses a large dataset (65535 keys) and runs multiple iterations to ensure that the results are representative. This helps to reduce variability and provide more accurate comparisons between the two approaches. **Alternative Approaches** There are other data structures that could be used for this benchmark, such as: * **Arrays**: Using an array of objects or a map-like object (e.g., `Map` or `WeakMap`) instead of a plain object. * **Set-based Data Structures**: Using a set-based data structure like a `Set` or a `MutableSet` to store the keys and values. However, these alternatives may not provide the same level of insight into the performance differences between `Map` and `Object` as this benchmark does.
Related benchmarks:
Map vs Object (real-world) Performance 2
Long int keys (19 digits) (one select)
Map vs Object (real-world) Performance (better)
Map vs Object (real-world) Performance - Forked
Comments
Confirm delete:
Do you really want to delete benchmark?