Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
delete vs null vs undefined vs void 0 vs Object.create(null) v2
(version: 0)
delete vs null vs undefined vs void 0 vs Object.create(null)
Comparing performance of:
null vs undefined vs Object.create(null) vs void 0 vs delete
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
null
var a = 999; for(var i = 0; i < 1000;i++) { a = null; }
undefined
var a = 999; for(var i = 0; i < 1000;i++) { a = undefined; }
Object.create(null)
var a = 999; for(var i = 0; i < 1000;i++) { a = Object.create(null); }
void 0
var a = 999; for(var i = 0; i < 1000;i++) { a = void 0; }
delete
var a = 999; for(var i = 0; i < 1000;i++) { delete a; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
null
undefined
Object.create(null)
void 0
delete
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Whale/3.5.3.2 Safari/537.36
Browser/OS:
Chrome 120 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
null
1909969.9 Ops/sec
undefined
6390.0 Ops/sec
Object.create(null)
5487.3 Ops/sec
void 0
1957973.5 Ops/sec
delete
1959100.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the provided benchmark definition and explain what is tested, compared, and considered. **Benchmark Definition** The website measures the performance of four different approaches to delete or unset variables in JavaScript: 1. `delete` (deletion) 2. `null` 3. `undefined` 4. `void 0` (equivalent to `undefined`) 5. `Object.create(null)` (creation of a new object with no prototype) These approaches are compared in the context of assigning a value to a variable and then deleting or unsetting it. **Options Compared** The options compared can be summarized as follows: * **Deletion (`delete`)**: Directly deletes the variable from memory. * **Null (`null`)**: Assigns `null` to the variable, which does not affect the variable's existence in memory but marks its last use. * **Undefined (`undefined`)**: Assigns `undefined` to the variable, similar to null, but it is considered undefined by JavaScript and can be detected using various methods (e.g., `typeof`, `isNaN`). * **Void 0 (`void 0`)**: Similar to `undefined`, but some browsers might optimize this to a null check due to its similarity in appearance. * **Object.create(null)`**: Creates a new object with no prototype chain, which can be used to unset the variable without deleting it from memory. However, this approach is slower compared to direct deletion. **Pros and Cons** Here's a brief summary of the pros and cons for each option: 1. **Deletion (`delete`)**: * Fastest ( O(1) ) * Most efficient * Does not preserve variable's memory location 2. **Null (`null`)**: * Faster than `undefined` * Preserves variable's memory location (can be accessed using `in`) 3. **Undefined (`undefined`)**: * Similar to null, but detectable using various methods * Slower than deletion and null assignments 4. **Void 0 (`void 0`)**: * May be optimized to a null check in some browsers * Unpredictable performance due to browser optimizations 5. **Object.create(null)`**: * Preserves variable's memory location (can be accessed using `in`) * Slower than direct deletion and null assignments **Special JavaScript Features** The test cases use special JavaScript features, including: 1. `delete`: Directly deletes the variable. 2. `typeof` and `isNaN`: Used to detect if a variable is undefined or not. These features are used within the benchmark definition to compare the performance of each option. **Other Alternatives** Some alternative approaches that could be considered in this benchmark include: 1. Using `delete` on an object property instead of a global variable. 2. Using a WeakMap or WeakSet to store variables and then deleting them. 3. Using a different data structure, such as an array, to store variables and then deleting them. However, these alternatives are not included in the provided benchmark definition and would require additional setup and testing. Overall, this benchmark provides valuable insights into the performance characteristics of different approaches to delete or unset variables in JavaScript, helping developers make informed decisions when working with these features.
Related benchmarks:
Object property: delete vs undefined 2
Object.create(null) vs Object literal
void 0 vs undefined
Delete vs Undefined
void 0 vs undefined vs variable containing undefined
Comments
Confirm delete:
Do you really want to delete benchmark?