Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object creation: new, object.create, literal+proto
(version: 2)
Comparing performance of:
new vs object.create vs object literal+proto vs object.create+object.assign
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function Thing() { this.prop1 = 0; this.prop2 = false; } Thing.prototype.doSomething = function () { this.prop1 = 1; this.prop2 = true; }; let proto = { doSomething() { this.prop1 = 1; this.prop2 = true; } } function createThing() { return Object.create(proto, { prop1: { value: 0, writable: true }, prop2: { value: false, writable: true } }); } function literalThing() { return { prop1: 0, prop2: false, __proto__: proto }; } function createAndAssignThing() { return Object.assign(Object.create(proto), { prop1: 0, prop2: false }); }
Tests:
new
new Thing();
object.create
createThing();
object literal+proto
literalThing();
object.create+object.assign
createAndAssignThing();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
new
object.create
object literal+proto
object.create+object.assign
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):
Measuring the performance of object creation methods in JavaScript can be an interesting and useful benchmark. **Benchmark Purpose:** The primary goal of this benchmark is to compare the execution speed of three different methods for creating objects: 1. `new` (using the `new` keyword) 2. `object.create` 3. `object literal + proto` (using object literals with prototype inheritance) These methods are compared to see which one is the fastest and most efficient. **Options Compared:** * **`new`**: Using the `new` keyword to create a new object instance. + Pros: - Easy to understand and use for simple object creation. - Can be used with inheritance (e.g., `class` syntax). + Cons: - May incur additional overhead due to prototype chain lookup. * **`object.create`**: Using the `Object.create()` method to create a new object instance from a prototype. + Pros: - Allows for more control over prototype inheritance and object creation. - Can be used with ES6 classes (using `class` syntax). + Cons: - May require more code to achieve the same result as `new`. * **`object literal + proto`**: Using object literals with prototype inheritance (`__proto__` property set to a prototype object). + Pros: - Can be used with minimal code changes from existing codebases. - Allows for fast and efficient object creation. **Library/Techniques Used:** * `Object.create()` method (used in `object.create` test case) * Object literals with prototype inheritance (`__proto__` property set to a prototype object) (used in `object literal + proto` test case) **Special JavaScript Feature/Syntax:** None mentioned. **Other Considerations:** * The benchmark only tests the creation speed of objects, not their behavior or functionality. * The results may vary depending on the specific use case and requirements. * This benchmark does not cover other aspects of object creation, such as assigning properties or methods to created objects. **Alternative Benchmarks:** There are other benchmarks that compare object creation methods, such as: * V8 Benchmark Suite (used in Node.js) * Benchmark.js * MicroBench These benchmarks may have different test cases and focus areas, but they all aim to provide a comprehensive understanding of JavaScript performance.
Related benchmarks:
Thingie
Create object
Object.assign vs direct assign
javascript new vs Object.create 2
javascript new vs Object.create 3
Comments
Confirm delete:
Do you really want to delete benchmark?