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)
(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
Created:
8 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; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
null
undefined
Object.create(null)
void 0
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
null
3435815.5 Ops/sec
undefined
1468492.4 Ops/sec
Object.create(null)
70981.4 Ops/sec
void 0
3472581.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **What is tested?** The provided JSON represents four individual test cases, each designed to measure the performance difference between different approaches for assigning a null or void value to a variable in JavaScript. The test cases are: 1. `delete vs null vs undefined vs void 0 vs Object.create(null)` Each test case involves creating a variable `a` and then repeatedly reassigning it with one of the following values: `null`, `undefined`, `void 0` (equivalent to `null` in some browsers), or using `Object.create(null)`. **Options compared** The four options being compared are: 1. **`delete`**: The `delete` operator is used to remove a property from an object, but it's not directly applicable to variables. 2. **`null`**: Assigning the value `null` to a variable. 3. **`undefined`**: Assigning the value `undefined` to a variable. 4. **`void 0`** (equivalent to `null` in some browsers): This is a way to assign the null value to a variable, but its usage can vary between browsers. 5. **`Object.create(null)`**: Creating an object with no prototype using `Object.create(null)`, and then assigning it to the variable. **Pros and Cons of each approach** Here's a brief overview of the pros and cons of each approach: 1. **`delete`**: Not applicable to variables, so not relevant in this context. 2. **`null`**: Simple and straightforward, but may have performance implications due to its use as an object property. 3. **`undefined`**: Similar to `null`, but with the added complexity of being a primitive value that can be used for other purposes (e.g., as a function parameter). 4. **`void 0`** (equivalent to `null` in some browsers): May have performance implications due to its use as an object property, and its usage is browser-dependent. 5. **`Object.create(null)`**: Creates an object with no prototype, which can be beneficial for certain use cases (e.g., creating a new object without inheriting from another). However, it may introduce additional overhead compared to assigning `null`. **Library usage** None of the provided benchmark definitions explicitly use any external libraries. However, using such libraries could potentially impact the results and add additional complexity. **Special JS features or syntax** This benchmark doesn't explicitly use any special JavaScript features or syntax, so we won't delve into that aspect. **Other alternatives** To measure similar performance characteristics, you could consider alternative approaches: 1. Assigning a falsy value (e.g., `false`, `0`, `-0`) to the variable. 2. Creating an object with no properties using `{}` and assigning it to the variable. 3. Using a custom object literal constructor to create an object without a prototype. Keep in mind that these alternatives might not directly compare to the original test cases, so you may need to adjust or modify them to achieve comparable results. Overall, this benchmark provides a useful comparison of different approaches for assigning null-like values to variables in JavaScript, highlighting potential performance implications and browser-dependent differences.
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?