Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object (R+W) 100k
(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 = 100000; 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:
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmarking test case, specifically designed to compare the performance of `Map` and `Object` data structures in JavaScript when used for read-write operations. **What is being tested?** Two test cases are compared: 1. **Map**: A `Map` object is created, and then 100,000 elements are set using the `set()` method, with keys generated by concatenating an integer with a string. After setting all elements, another 100,000 iterations retrieve elements using the `get()` method. 2. **Object**: An empty `Object` is created, and then 100,000 key-value pairs are added using the syntax `object[key] = value`. After adding all pairs, another 100,000 iterations retrieve values using the same syntax. **Options being compared** Two main options are compared: * **Map**: A built-in JavaScript data structure that stores keys as strings and values as arbitrary JavaScript objects. * **Object**: A native JavaScript data structure that stores key-value pairs using dot notation (e.g., `object[key] = value`). **Pros and Cons of each approach** 1. **Map**: * Pros: Faster lookups and insertions, as it uses a hash table to store keys. * Cons: Requires additional memory for storing the map's internal state. 2. **Object**: * Pros: Can be more concise and readable in some cases, as it allows using dot notation. * Cons: Less efficient than Map for large datasets or frequent lookups, due to its object-based storage. **Special consideration** The test case uses a string concatenation technique (`(i * 10000).toString()`) to generate keys, which is not the most efficient way to create a large number of strings in JavaScript. This can lead to slower performance compared to using other methods, such as `Math.floor(Math.random() * 100000)`. **Library used** None. **Special JavaScript feature or syntax** The test case uses string concatenation (`+`) to concatenate integers and strings, which is not the most efficient way to create a large number of strings in JavaScript. This can lead to slower performance compared to using other methods. **Other alternatives** For similar benchmarks: * **Array**: Using an array as a data structure for storing key-value pairs. * **Set**: Using a `Set` object for storing unique values, which might be more efficient than Map for some use cases. * **IndexedDB**: A low-level database API that provides better performance and control over data storage compared to the built-in data structures. Keep in mind that these alternatives may have different pros and cons depending on the specific use case.
Related benchmarks:
Map vs Object (real-world) Performance
Large Map vs Object 2
Map vs Object (real-world) Performance 2
Map vs Object read performance for a 1000 key lookup
Map vs Object (real-world) Performance - Forked
Comments
Confirm delete:
Do you really want to delete benchmark?