Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Delete entries from object vs from map
(version: 0)
Deleting entries from an object vs from a Map
Comparing performance of:
Object vs Map
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Object
const keys = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; const data = {}; keys.forEach(key => { data[key] = key; }); delete data['1']; delete data['2']; delete data['3']; delete data['4'];
Map
const keys = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ]; const mapData = new Map(); keys.forEach(key => { mapData.set(key, key); }); mapData.delete('1'); mapData.delete('2'); mapData.delete('3'); mapData.delete('4');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object
Map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0
Browser/OS:
Firefox 136 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object
1712777.5 Ops/sec
Map
1302606.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the test cases and explain what's being tested, the pros and cons of different approaches, and other considerations. **Benchmark Definition** The benchmark definition is comparing two ways to delete entries from an object (JavaScript native type) vs a Map (built-in JavaScript data structure). The goal is to determine which method is faster. **Script Preparation Code** The script preparation code is empty for both test cases. This means that the initial state of the object and map is not modified before running the benchmark. **Individual Test Cases** There are two test cases: 1. **Object** ```javascript const keys = [\r\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\r\n]; \r\n\rnconst data = {}; \r\n\rnkeys.forEach(key => {\r\n data[key] = key;\r\n}); \r\n\rndelete data['1']; \rndelete data['2']; \rndelete data['3']; \rndelete data['4']; ``` This script creates an object `data` and populates it with keys from the array. It then deletes three entries using the dot notation (`delete data[key]`) for each key. 2. **Map** ```javascript const keys = [\r\n 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,\r\n]; \r\n\rnconst mapData = new Map(); \r\n\rnkeys.forEach(key => {\r\n mapData.set(key, key);\r\n}); \r\n\rnymapData.delete('1'); \rnmimapData.delete('2'); \rnmimapData.delete('3'); \rnmimapData.delete('4'); ``` This script creates a Map `mapData` and populates it with keys from the array. It then deletes three entries using the `delete()` method for each key. **Pros and Cons** 1. **Object (dot notation)**: * Pros: Simple, widely supported, and easy to use. * Cons: May be slower due to the overhead of accessing properties via a string. 2. **Map (delete())**: * Pros: Faster, more efficient, and optimized for delete operations. * Cons: Requires creating an instance of Map, which may incur additional overhead. In general, Maps are designed to provide fast lookups and deletions, making them suitable for use cases where these operations are frequent. However, in this specific benchmark, the difference between dot notation and `delete()` is relatively small, suggesting that the performance advantage of using a Map is not drastic. **Other Considerations** * **Library usage**: Neither test case uses any external libraries. * **Special JS features**: There are no special JavaScript features or syntax used in these test cases (e.g., async/await, Promises). * **Alternatives**: Other alternatives for deleting entries from an object include using `Object.keys()` and the `forEach` method to iterate over an array of keys, or using `delete` with a variable that holds the key. Keep in mind that benchmarking results can vary depending on specific use cases, hardware, and software configurations. These results should be considered as a starting point for further investigation and may need to be adjusted based on specific requirements.
Related benchmarks:
Delete vs destructure for objects
Delete vs destructure for objects in loop
Map vs object for deletions
Map.delete(key) VS Map.set(key, null)
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?