Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object creation speed benchmark
(version: 0)
Comparing performance of:
new operator vs Object.create function
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var A = (function () { function A(b) { this.b = b; } return A; }());
Tests:
new operator
new A(1);
Object.create function
Object.create(A.prototype, {a: {value: 1}});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new operator
Object.create function
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Browser/OS:
Chrome 139 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new operator
113798032.0 Ops/sec
Object.create function
2545639.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **Benchmark Definition** The benchmark is designed to measure the speed of object creation in JavaScript using two different approaches: the `new` operator and the `Object.create()` function. **Options being compared** Two options are being compared: 1. **`new` operator**: This is a built-in JavaScript operator that creates a new object and returns it. 2. **`Object.create()` function**: This function creates a new object and sets its prototype to the specified object. **Pros and Cons of each approach** * `new` operator: + Pros: Simple, concise, and widely supported. + Cons: Can be slower due to the overhead of creating a new object and initializing its properties. * `Object.create()` function: + Pros: More flexible and can be used to create objects with specific prototypes or inheritance chains. + Cons: Requires specifying the prototype explicitly, which can be more error-prone. **Library usage** There is no explicit library mentioned in the benchmark definition. However, the use of the `Object.create()` function suggests that JavaScript's built-in object creation mechanisms are being utilized. **Special JS features or syntax** No special JavaScript features or syntax are being used in this benchmark. The code is straightforward and uses only standard JavaScript constructs. **Other alternatives** In addition to the `new` operator and `Object.create()` function, other approaches could be considered for creating objects in JavaScript: * **Constructor functions**: Using a function declaration with the same name as the object being created. * **Prototypal inheritance**: Creating objects by extending an existing prototype using the `proto` property. However, these alternatives are not explicitly mentioned in the benchmark definition and may not provide significant performance benefits or advantages over the `new` operator and `Object.create()` function. **Benchmark preparation code** The provided script preparation code creates a new object `A` with a single method `b`, which takes an argument. This is done using a self-invoking anonymous function expression, where the constructor function is defined immediately within the outer function call. The resulting object `A` is then returned and assigned to the variable `A`. **Individual test cases** There are two individual test cases: 1. **`new operator`**: Creates an instance of the `A` object using the `new` operator. 2. **`Object.create()` function**: Creates a new object by specifying the prototype and properties using the `Object.create()` function. These test cases measure the speed of creating objects using each approach. **Latest benchmark result** The latest benchmark results show that the Chrome 113 browser executing on a Mac OS X 10.15.7 desktop device achieved higher execution rates for both test cases, with approximately 32182120 executions per second and 3750929 executions per second respectively. Keep in mind that these results may vary depending on the specific environment and hardware configuration used to run the benchmark.
Related benchmarks:
object create vs others
Object.assign() vs spread operator (New object)
javascript new vs Object.create 2
javascript new vs Object.create 3
Comments
Confirm delete:
Do you really want to delete benchmark?