Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Proxy vs Object vs Object.setPrototypeOf vs Object.create
(version: 0)
Comparing performance of:
Basic vs Proxy vs Proto vs Object.create
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
window.basic = {a : 1, b: 2}; window.proxy = new Proxy({a : 1, b: 2}, {get : (t, p) => t[p]}) window.proto = Object.setPrototypeOf({}, {a : 1, b: 2}) window.create = Object.assign(Object.create(Object.getPrototypeOf({})), {a : 1, b: 2})
Tests:
Basic
let a = basic.a; let b = basic.b;
Proxy
let a = proxy.a; let b = proxy.b;
Proto
let a = proto.a; let b = proto.b;
Object.create
let a = create.a; let b = create.b;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Basic
Proxy
Proto
Object.create
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
Basic
78862568.0 Ops/sec
Proxy
10050812.0 Ops/sec
Proto
109049048.0 Ops/sec
Object.create
100598160.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested, compared options, their pros and cons, and other considerations. **Benchmark Definition** The test case measures the performance difference between four different approaches to create an object with similar properties: 1. **Proxy**: A proxy object created using the `Proxy` constructor. 2. **Object**: An object created directly using the `{}` syntax. 3. **Proto**: An object created by setting its prototype using `Object.setPrototypeOf`. 4. **Object.create**: An object created using `Object.assign` and `Object.create`. **Test Cases** The test case consists of four individual tests, each measuring the performance of one approach: 1. **Basic**: Measures the performance of directly creating an object with properties `a` and `b`. 2. **Proxy**: Measures the performance of creating a proxy object with properties `a` and `b`. 3. **Proto**: Measures the performance of setting the prototype of an object to create it with properties `a` and `b`. 4. **Object.create**: Measures the performance of using `Object.assign` and `Object.create` to create an object with properties `a` and `b`. **Library Used:** * No external libraries are used in this benchmark. **Special JS Features/Syntax:** None mentioned. **Other Considerations:** * The benchmark measures executions per second, which is a common metric for performance testing. * The test cases are designed to be independent, allowing for a fair comparison of the four approaches. * The use of `Object.setPrototypeOf` and `Object.assign` provides a way to create objects with similar properties without having to duplicate code. **Pros and Cons:** 1. **Proxy**: * Pros: Provides a way to create objects with complex behaviors using a callback function. * Cons: Can introduce additional overhead due to the creation of a proxy object. 2. **Object**: * Pros: Simple and straightforward, creates an object directly without any overhead. * Cons: May not be suitable for all use cases where more complex behavior is required. 3. **Proto**: * Pros: Allows for fine-grained control over the creation of objects by setting their prototype. * Cons: Can be error-prone if not used correctly, and may introduce additional overhead due to the creation of a new object. 4. **Object.create**: * Pros: Provides a way to create objects with similar properties using `Object.assign`, which can be more efficient than creating objects directly. * Cons: May require additional setup and configuration, and can be less intuitive for some developers. In general, the choice of approach depends on the specific use case and requirements. For simple cases where direct object creation is sufficient, **Object** may be the most suitable option. For more complex scenarios where custom behavior or manipulation of properties is required, **Proxy**, **Proto**, or **Object.create** might be a better fit. Other alternatives that could be used to create objects with similar properties include: * Using a constructor function to create objects. * Using a class-based approach (e.g., with ES6 classes) to create objects. * Utilizing other library functions, such as `lodash`'s `assign` or `cloneDeep`, to create objects. However, the choice of alternative depends on the specific requirements and constraints of the project.
Related benchmarks:
Window Perf
Proxy vs Object vs Object.setPrototypeOf
Object.setPrototypeOf vs Object literal
Proxy.get(prop) vs obj[prop]
Comments
Confirm delete:
Do you really want to delete benchmark?