Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
javascript new vs Object.create
(version: 0)
Comparing performance of:
Object.create vs new
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
//var opt = {} function Foo() {} var Bar = {};
Tests:
Object.create
let bar = Object.create(Bar);
new
let foo = new Foo();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.create
new
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.create
97474504.0 Ops/sec
new
89402632.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its results. **Benchmark Overview** The test compares two JavaScript syntax approaches to create an object: `new` (with classes) and `Object.create`. The goal is to measure their performance. **Options Compared** Two options are being compared: 1. **New**: This approach uses the `new` keyword with a class constructor (`Foo`) to create a new instance of the `Bar` object. The syntax is `let foo = new Foo();`. 2. **Object.create**: This approach uses the `Object.create()` method, passing an existing object (`Bar`) as its first argument. The syntax is `let bar = Object.create(Bar);`. **Pros and Cons** * **New:** * Pros: * More modern, standardized way of creating objects with classes. * Less boilerplate code required. * Cons: * Requires support for ES6+ syntax (classes). * Potential performance overhead due to class instantiation. * **Object.create**: * Pros: * Older syntax that is still widely supported across browsers. * No performance overhead from class instantiation. * Cons: * Less modern and less standardized than the `new` approach. **Library and Purpose** The `Foo` constructor function is used to create a simple object. In this context, its purpose is only to demonstrate the creation of an object using the `new` keyword. The actual functionality of `Foo` is not being tested or compared; it's just a utility for creating objects with classes. **Special JS Feature/Syntax** Neither the `new` nor the `Object.create` approaches require special JavaScript features or syntax beyond standard ES6+ and older syntax support. They are both relatively straightforward in terms of required language features. **Other Alternatives** Some other alternatives to create an object include: * Function constructor: `let bar = new Bar();` * Constructor functions (before classes): `Bar.prototype.bar = function(){}; let bar = new Bar();` * Immediately Invoked Function Expression (IIFE) with a function that returns an object: `(function(){return {}})()`
Related benchmarks:
object create vs others
Object.create(null) vs Object literal
javascript new vs Object.create 2
javascript new vs Object.create 3
Comments
Confirm delete:
Do you really want to delete benchmark?