Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object create null
(version: 0)
Comparing performance of:
object create null vs object vs new
Created:
9 years ago
by:
Guest
Jump to the latest result
Tests:
object create null
var a = []; for (i = 0; i < 10000; i++) a.push( Object.create(null) )
object
var a = []; for (i = 0; i < 10000; i++) a.push( {} );
new
var a = []; for (i = 0; i < 10000; i++) a.push( new Object() );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
object create null
object
new
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
object create null
2886.7 Ops/sec
object
3932.4 Ops/sec
new
3424.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in these JavaScript microbenchmarks. **Benchmark Overview** The tests are designed to measure the performance of object creation in three different ways: 1. Using `Object.create(null)` (Test Case: "object create null") 2. Using an empty object literal `{}` (Test Case: "object") 3. Using the `new` keyword with an empty object constructor (`new Object()` ) (Test Case: "new") **What's Being Tested** Each test case creates an array of a specified number of objects (10,000 in this case) and measures how fast each method can create these objects. **Options Compared** The three options are compared for their performance: 1. `Object.create(null)`: This method creates a new object without any prototype chain. It's the fastest way to create an object with no inheritance. 2. `{}`: An empty object literal creates a new object with the default prototype chain set by JavaScript. It's slightly slower than `Object.create(null)` but still efficient. 3. `new Object()`: This method creates a new instance of the `Object` constructor, which inherits from the global `Object.prototype`. It's the slowest way to create an object due to the overhead of inheritance. **Pros and Cons of Each Approach** Here are some pros and cons for each approach: 1. `Object.create(null)`: * Pros: Fastest, no inheritance, suitable for cases where no prototype chain is needed. * Cons: Some older browsers may not support it (pre-ES6). 2. `{}`: * Pros: Widespread support in modern browsers, efficient performance. * Cons: Inherits from the global `Object.prototype`, which might be slower for large objects. 3. `new Object()` : * Pros: Widely supported across browsers and environments, suitable for cases where inheritance is needed. * Cons: Slowest due to overhead of prototype chain. **Library/Extension Used** None are explicitly mentioned in the provided code snippets. However, it's likely that the tests are running on a vanilla JavaScript engine or a custom implementation. **Special JS Features/Syntax** There are no special features or syntax used in these benchmarks. They are standard JavaScript constructs, making them easy to understand and implement for anyone familiar with the language. **Alternatives** For benchmarking object creation performance, you might consider using other libraries or frameworks like: 1. V8 Benchmark Suite (for Chrome-specific tests) 2. WebAssembly Benchmarks (for comparing different Wasm implementations) Keep in mind that these alternatives are specific to particular use cases and might not be directly comparable to the provided JavaScript microbenchmarks. Overall, these benchmarks provide a straightforward comparison of three common ways to create objects in JavaScript, highlighting their relative performance and trade-offs.
Related benchmarks:
Thingie
undefined vs. typeof vs. in vs. hasOwnProperty (Object.create(null))
Object.create(null) vs Object literal
Object literal vs Object.create(null) v4
Object literal vs Object.create(null) v4 13.07.2023
Comments
Confirm delete:
Do you really want to delete benchmark?