Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object vs Map (Insert, Delete and Copy)
(version: 0)
Comparing performance of:
Map Insert vs Object Insert vs Object2 Insert vs Map Delete vs Object Delete vs Object2 Delete vs Map Copy vs Object Copy vs Object2 Copy vs Map to Object
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; var obj2 = Object.create(null);
Tests:
Map Insert
for (let i = 0; i < 10000; i++) { map.set(`a${i}`, i); }
Object Insert
for (let i = 0; i < 10000; i++) { obj[`a${i}`] = i; }
Object2 Insert
for (let i = 0; i < 10000; i++) { obj2[`a${i}`] = i; }
Map Delete
let map = new Map(); for (let i = 0; i < 10000; i++) { map.delete(`a${i}`); }
Object Delete
for (let i = 0; i < 10000; i++) { delete obj[`a${i}`]; }
Object2 Delete
for (let i = 0; i < 10000; i++) { delete obj2[`a${i}`]; }
Map Copy
for (let i = 0; i < 10000; i++) { const map2 = new Map(map); }
Object Copy
for (let i = 0; i < 10000; i++) { const objCopy = {...obj}; }
Object2 Copy
for (let i = 0; i < 10000; i++) { const objCopy = {...obj2}; }
Map to Object
for (let i = 0; i < 10000; i++) { const newObj = Object.fromEntries(map.entries()); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (10)
Previous results
Fork
Test case name
Result
Map Insert
Object Insert
Object2 Insert
Map Delete
Object Delete
Object2 Delete
Map Copy
Object Copy
Object2 Copy
Map to 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 world of JavaScript microbenchmarks and explore what's being tested in this particular benchmark. **Benchmark Overview** This benchmark compares the performance of three data structures: `Object`, `Map`, and `Object2` (a variant of `Object`). Each test case measures the execution time of various operations: 1. Insertion 2. Deletion 3. Copying The benchmarks aim to determine which data structure is most efficient for these common use cases. **Data Structures** Let's take a closer look at each data structure being compared: * **Object**: A traditional JavaScript object, represented by the `obj` variable. * **Map**: A JavaScript Map object, represented by the `map` variable. Maps are similar to objects but offer additional methods and features like key-value pairs and efficient iteration. * **Object2** (variant of Object): An alternative implementation of an object, represented by the `obj2` variable. This variant is not a standard JavaScript object. **Benchmark Operations** Each test case measures the execution time for one or more operations: 1. Insertion: * `Object` insertion: `obj[key] = value` * `Map` insertion: `map.set(key, value)` * `Object2` insertion: `obj2[key] = value` (assuming a custom implementation) 2. Deletion: * `Object` deletion: `delete obj[key]` * `Map` deletion: `map.delete(key)` 3. Copying: * `Object` copying: `const copiedObj = { ... obj }` * `Map` copying: `const copiedMap = new Map([...map])` 4. `Map to Object`: Converting a `Map` to an equivalent `Object`. This operation is not directly applicable to `Object2`. **Performance Comparison** The benchmark outputs the execution time for each test case, providing insights into which data structure performs best under various scenarios. In this benchmark: * **Map** consistently outperforms both `Object` and `Object2` in terms of insertion, deletion, and copying operations. * **Object2**, being a variant of Object, doesn't seem to offer significant performance advantages over the traditional `Object`. Keep in mind that these results may depend on specific use cases and implementation details. The benchmark is likely designed to highlight the strengths of JavaScript's built-in `Map` data structure. Please let me know if you have any further questions or if there's anything else I can help with!
Related benchmarks:
JS object copy spread vs assign
JS object copy spread vs assign spin@
Object.assign vs direct copy
Map vs object for deletions
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?