Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object (R+W) 1k
(version: 0)
Read/Write of Map vs Object (competition use only, please don't use these in the real world).
Comparing performance of:
Map vs Object
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; var count = 1000; var i = 0, a;
Tests:
Map
for (i = 0; i < count; i++) { map.set((i * 10000).toString(), i); } for (i = 0; i < count; i++) { a = map.get((i * 10000).toString()); }
Object
for (i = 0; i < count; i++) { obj[(i * 10000).toString()] = i; } for (i = 0; i < count; i++) { a = obj[(i * 10000).toString()]; }
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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map
4415.9 Ops/sec
Object
3217.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what is being tested. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that tests two approaches for storing and retrieving data: Maps (using the `Map` object) and Objects (using the built-in Object literal syntax). The test creates 1000 key-value pairs, where each key is a string representation of a large number (e.g., "10000") and the value is an integer. It then measures the time it takes to set and retrieve these values using both approaches. **Options compared** The two options being compared are: 1. **Map**: Using the `Map` object, which provides a built-in way to store key-value pairs. 2. **Object**: Using the built-in Object literal syntax (e.g., `obj[key] = value`) to store and retrieve data. **Pros and Cons of each approach** * **Map**: + Pros: Maps provide an efficient way to store and retrieve data using keys, with O(1) lookup times. + Cons: Maps are not natively supported in older browsers (pre-ECMAScript 2015), and may have additional overhead due to the complexity of the `Map` object implementation. * **Object**: + Pros: Objects are widely supported across all modern browsers, with O(1) lookup times using bracket notation (`obj[key]`). + Cons: Using bracket notation can be slower than using a Map for large datasets, as it requires iterating over the keys to find the correct value. **Other considerations** * **Library usage**: Neither of these approaches uses any external libraries. * **JavaScript features**: This benchmark does not use any special JavaScript features or syntax beyond what is required by the test case (e.g., no ES6+ features like async/await). **Alternative approaches** Other alternatives for storing and retrieving data in JavaScript include: 1. **Arrays**: Using arrays with index-based access can be slower than using Maps or Objects, especially for large datasets. 2. **Sparse Arrays**: If you need to store a limited number of values, sparse arrays (i.e., arrays with holes) might be faster due to reduced memory usage and faster indexing. Keep in mind that the performance difference between these approaches will vary depending on the specific use case, dataset size, and browser or environment being used.
Related benchmarks:
Map vs Object (real-world) Performance
Large Map vs Object 2
Map vs Object read performance for a 1000 key lookup
Map vs Object (real-world) Performance - Forked
Map vs Object (real-world) Performance - Forked2
Comments
Confirm delete:
Do you really want to delete benchmark?