Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map.delete(key) VS Map.set(key, null)
(version: 0)
https://www.measurethat.net/Benchmarks/Show/12770/0/delete-vs-null, but with Maps
Comparing performance of:
Map.delete(key) vs Map.set(key, null)
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); for (let i = 0; i < 1000; i++) { map.set(i, {}); }
Tests:
Map.delete(key)
for(const key of map.keys()) { map.delete(key); }
Map.set(key, null)
for(const key of map.keys()) { map.set(key, null); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map.delete(key)
Map.set(key, null)
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):
I'd be happy to explain the benchmark and its results. **Benchmark Overview** The benchmark compares two approaches for updating a Map in JavaScript: `map.set(key, null)` vs `map.delete(key)`. The goal is to measure which approach is faster. **Options Compared** Two options are compared: 1. **`map.set(key, null)`**: This approach uses the `set()` method of the Map interface to set the value associated with a key to `null`. 2. **`map.delete(key)`**: This approach uses the `delete()` method of the Map interface to remove an entry from the map. **Pros and Cons** * **`map.set(key, null)`**: + Pros: This approach is straightforward and easy to understand. It's also a common way to "delete" a value in JavaScript. + Cons: If you're trying to actually delete a key-value pair, this approach might be slower than `map.delete(key)`. * **`map.delete(key)`**: + Pros: This approach is specifically designed for deleting keys from the map. It's likely to be faster since it only removes the entry without creating a new one. + Cons: This approach can be confusing if you're not used to using `delete()` on Maps. **Other Considerations** * **Library Usage**: The benchmark uses the built-in JavaScript Map object, which is supported by most modern browsers and Node.js environments. * **Special JS Feature/Syntax**: There are no special features or syntaxes being tested in this benchmark. It's purely focused on comparing two common approaches to updating a Map. **Benchmark Preparation Code** The script preparation code creates an empty Map `map` and sets 1000 key-value pairs using `map.set(i, {})`. The HTML preparation code is not provided, which suggests that the test doesn't require any additional setup or rendering elements. **Individual Test Cases** There are two individual test cases: 1. **`Map.delete(key)`**: This test case runs a loop over all keys in the map and deletes each key using `map.delete(key)`. 2. **`Map.set(key, null)`**: This test case runs a loop over all keys in the map and sets each key to `null` using `map.set(key, null)`. **Latest Benchmark Result** The latest benchmark result shows that: * **`Map.set(key, null)`**: Executes approximately 23235830 times per second. * **`Map.delete(key)`**: Executes approximately 22506002 times per second. This suggests that `map.set(key, null)` is slightly faster than `map.delete(key)`. However, please note that these results might not be representative of your specific use case or environment.
Related benchmarks:
Map vs object for deletions
Array from() vs Map.keys()
delete operator VS Map.delete
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?