Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Map vs Object - Write
(version: 0)
Benchmark.js
Write of map vs object
Comparing performance of:
Map write vs Obj write
Created:
3 years ago
by:
Guest
Go to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; var i = 0, count = 1000;
Tests:
Map write
for (i = 0; i < count; i++) { map.set(i+'', i); }
Obj write
for (i = 0; i < count; i++) { obj[i+''] = i; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map write
Obj write
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 123 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Obj write
767/s
Map write
753/s
View exact numbers
Test name
Executions per second
✓
Obj write
767 Ops/sec
Map write
753 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark compares the performance of two data structures in JavaScript: Maps (a built-in JavaScript object that stores key-value pairs) and plain objects (also known as hash tables or dictionaries). The goal is to measure how efficiently each structure can write (insert) 1,000 key-value pairs. **Options Compared** There are only two options being compared: 1. **Map Write**: Using a Map to store the key-value pairs. 2. **Object Write**: Using a plain object to store the key-value pairs. **Pros and Cons of Each Approach** **Map Write:** Pros: * Maps provide efficient lookups, insertions, and deletions using their built-in `set()` method, which can lead to better performance in certain scenarios. * Map objects are dynamic, meaning they can handle changes without requiring explicit updates. Cons: * Maps require an additional overhead for storing the keys (using integers) compared to plain objects. * Map operations might be slower due to the need to store and retrieve the key-value pairs from a hash table. **Object Write:** Pros: * Plain objects are lightweight, with no additional overhead for storing keys. * Object operations like property assignment (`obj[key] = value`) can be faster since they don't require a separate data structure for storing keys. Cons: * Objects do not provide built-in support for efficient lookups, insertions, or deletions, requiring manual implementation using methods like `obj[key] = value` or object iteration. * Objects may incur additional overhead due to the need to store and retrieve property values from an array. **Library Used** None is explicitly mentioned in the benchmark definition. However, both Map and Object implementations rely on JavaScript's built-in data structures and objects. **Special JS Features/Syntax** There are no special JavaScript features or syntax being used in this benchmark. It only relies on standard JavaScript syntax for defining variables (e.g., `var map = new Map();`), loops (`for` loop), and assignment operations (`map.set()`). **Other Alternatives** In theory, other data structures like arrays, sets, or even custom-built hash tables could be used instead of Maps and objects. However, in JavaScript, these alternatives might not provide the same level of efficiency or convenience as using the built-in Map and Object implementations. Keep in mind that this benchmark is designed to test the performance of writing key-value pairs into a data structure, which can have implications for various use cases like caching, data storage, or high-performance applications.
Related benchmarks
Object spread vs new Map vs Object assign with complex data
creating maps vs creating objects
Comments
Confirm delete:
Do you really want to delete benchmark?