Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object vs Map delete and lookup
(version: 0)
Comparing performance of:
Map lookup vs Object lookup vs Map delete vs Object delete
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.map = new Map(); window.obj = {}; for (let i = 0; i < 10000; ++i) { window.map.set(i, i); window.obj[i] = i; } window.result = undefined;
Tests:
Map lookup
for (let i = 0; i < 10000; ++i) { window.result = window.map.get(i) }
Object lookup
for (let i = 0; i < 10000; ++i) { window.result = window.obj[i]; }
Map delete
const mapCopy = new Map(window.map); for (let i = 0; i < 10000; ++i) { mapCopy.delete(i); }
Object delete
const objCopy = { ... window.obj }; for (let i = 0; i < 10000; ++i) { delete objCopy[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Map lookup
Object lookup
Map delete
Object delete
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0
Browser/OS:
Firefox 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map lookup
381.6 Ops/sec
Object lookup
562.2 Ops/sec
Map delete
1447.9 Ops/sec
Object delete
1460.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks! The provided JSON represents a benchmark test case on MeasureThat.net, which compares the performance of two data structures in JavaScript: objects and Maps. The test case is designed to measure the lookup time of elements in these data structures. **Data Structures Compared** Two data structures are compared: 1. **Objects**: A regular JavaScript object (`window.obj`) is used as the data structure. 2. **Maps**: A Map object (`window.map`) is used as the data structure. **Options Compared** The benchmark tests two options for each data structure: **Object Lookup** * Option 1: Direct access using `window.obj[i]`. * Option 2: Indirect access using `window.result` (initialized with an undefined value). **Map Delete** * Option 1: Deleting an element directly from the Map object using `map.delete(i)`. **Object Delete** * Option 1: Deleting an element from a copy of the object using `delete objCopy[i]`. **Pros and Cons of Each Approach** Here's a brief overview of each approach: * **Direct access in objects**: This is the most straightforward way to access an element in an object. However, it may incur additional overhead due to the need for type checking and potential caching. * **Indirect access in objects**: This approach uses a shared variable `window.result` to store the result of each lookup. While this reduces overhead, it introduces complexity and potential issues with thread safety. * **Deleting from Maps**: Deleting an element directly from a Map object is efficient and lightweight. * **Deleting from object copies**: Creating a copy of the object before deleting elements can help avoid modifying the original object while iterating over it. **Special JavaScript Features/ Syntax** In this benchmark, none of the special JavaScript features or syntax (e.g., async/await, promises, generator functions) are used. However, some optimization techniques like caching and type checking are implied by the use of shared variables like `window.result`. **Alternatives to MeasureThat.net** If you're interested in running similar benchmarks or comparing performance of other JavaScript features or data structures, here are a few alternatives: * **jsperf**: A classic benchmarking tool for JavaScript. * **Benchmark.js**: A more modern and flexible benchmarking library. * **Google's JavaScript Benchmark Suite**: A collection of benchmark tests for various aspects of JavaScript performance. These tools allow you to create and run custom benchmarks, comparing the performance of different code snippets or data structures.
Related benchmarks:
Object property: delete vs undefined 2
Delete vs destructure for objects in loop
delete property of object vs create new object
Delete vs Undefined
Delete vs Setting undefined
Comments
Confirm delete:
Do you really want to delete benchmark?