Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object vs Map lookup: random integer key
(version: 0)
Comparing performance of:
Map vs Object
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
window.m = new Map(); window.o = {}; for (let i = 100000; i < 100000000; i+=1000) { var j = Math.floor(Math.random()*999); window.m.set(i+j, [12345, 67890]) window.o[i+j] = [12345, 67890]; }
Tests:
Map
for (let i = 0; i < 100000; ++i) { arrayo = window.m.get(Math.floor(Math.random()*1000000)); }
Object
for (let i = 0; i < 100000; ++i) { arrayo = window.o[Math.floor(Math.random()*1000000)]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map
Object
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 dive into the benchmark and explore what's being tested. **Benchmark Overview** The benchmark measures the performance of two approaches to store and retrieve data: Objects (`window.o`) and Maps (`window.m`). The test case uses a large dataset of random integer keys with corresponding values, which are stored in both objects and maps. **Options Compared** Two options are compared: 1. **Objects (window.o)**: The benchmark tests how fast JavaScript can access a value by its key using an object. In this case, the `window.o` object is populated with 100 million entries, each with a random integer key and a value. 2. **Maps (window.m)**: The benchmark also tests how fast JavaScript can access a value by its key using a Map. Similarly, the `window.m` Map is populated with 100 million entries, each with a random integer key and a value. **Pros and Cons of Each Approach** Both objects and maps are suitable data structures for storing key-value pairs, but they have different performance characteristics: * **Objects**: Objects are more flexible and convenient to use, as they allow for dynamic property creation and don't require explicit key-value pairs. However, accessing an object's property by its key can be slower than using a Map. * **Maps**: Maps are optimized for fast lookups and provide a more efficient way to access values by their keys. They also allow for arbitrary key types (not just strings). In general, maps are faster when dealing with large datasets and multiple lookups, while objects might be preferred when the data structure needs to support other operations like property creation or method calls. **Library Usage** The benchmark uses two libraries: * None: There is no external library being used in this benchmark. The script and object manipulations are performed using standard JavaScript syntax. * `Math`: The `Math` library is used for mathematical functions like `floor()` and `random()`, which generate random numbers. **Special JS Features or Syntax** None of the benchmark code uses any special JavaScript features or syntax, such as async/await, Promises, or Web Workers. It's a simple, straightforward test case that focuses on basic object and map operations. **Alternatives** If you want to create similar benchmarks for other data structures, here are some alternatives: * **Arrays**: You can test the performance of accessing an element in an array by its index using `array[index]`. * **Sets**: Sets are another data structure that provides fast lookups. You can test their performance using a similar approach. * **WeakMaps**: WeakMaps are a type of Map that don't allow cycles, which makes them more suitable for certain use cases. Keep in mind that each benchmark should be tailored to the specific use case and requirements you want to test.
Related benchmarks:
Object vs Map lookup w/ rando integer keys
Object vs Map lookup w/ rando integer key
Object vs Map lookup w/ rando integer key and array
Map vs Object (real-world) Performance (non-numeric key)
Comments
Confirm delete:
Do you really want to delete benchmark?