Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Wrapping objects method removal performance
(version: 0)
Comparing performance of:
Proxy method vs Replaced method
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
class Parent { next = null constructor(next) { this.next = next } foo() { return "Parent" } optimize() { this.next?.optimize() } } class Wrapper extends Parent { foo() { return this.next.foo() } optimize() { this.next.optimize() this.foo = this.next.foo } } class Unwrappable extends Parent { foo() { return this.next.foo() } } class Child1 extends Parent { foo() { return "Child1" } } class Child2 extends Parent { foo() { return "Child2" } } var a = new Wrapper(new Unwrappable(new Wrapper(new Wrapper(new Unwrappable(new Wrapper(new Child2())))))) var b = new Wrapper(new Unwrappable(new Wrapper(new Wrapper(new Unwrappable(new Wrapper(new Child1())))))) b.optimize()
Tests:
Proxy method
for (let i = 0; i < 10; ++i) { if (a.foo() !== "Child2") { throw new Error("Unexpected result") } }
Replaced method
for (let i = 0; i < 10; ++i) { if (b.foo() !== "Child1") { throw new Error("Unexpected result") } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Proxy method
Replaced method
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Proxy method
1991505.1 Ops/sec
Replaced method
1564878.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript benchmark that tests the performance of two different approaches: using proxies (Proxy method) and replaced methods (Replaced method). **What is being tested?** The benchmark measures the performance of removing the `optimize()` method from the wrapper object. The test creates two objects, `a` and `b`, with different wrapping configurations: * `a` uses a proxy pattern to wrap an unwrappable object, which in turn wraps another unwrappable object. * `b` also uses a proxy pattern, but with the opposite order of wrapping. The benchmark checks that the wrapper methods are called correctly by checking if the wrapped objects return the expected results. If not, it throws an error. **Options compared** Two approaches are compared: 1. **Proxy method**: This approach uses the Proxy API to create a proxy object that wraps the unwrappable object. The proxy object has its own `foo()` and `optimize()` methods, which call the original methods on the wrapped objects. 2. **Replaced method**: In this approach, the wrapper object replaces the `foo()` method with its own implementation, which calls the `next.foo()` method. **Pros and Cons of each approach** * **Proxy method**: + Pros: - More flexible and modular, as the proxy object can be reused with different wrapping configurations. - Easier to test and debug, as the proxy object provides a clear separation between the wrapper and wrapped objects. + Cons: - May introduce additional overhead due to the creation of proxy objects. * **Replaced method**: + Pros: - More straightforward and simple, as it only involves replacing the `foo()` method with a new implementation. + Cons: - Less flexible and modular, as each wrapping configuration would require a separate implementation. **Library usage** The benchmark uses the Proxy API to create proxy objects. The Proxy API is a built-in JavaScript feature that allows you to create objects with custom properties and methods. **Special JS features or syntax** There are no special features or syntax used in this benchmark. It only uses standard JavaScript concepts and APIs, such as classes, functions, and the Proxy API. **Other alternatives** If alternative approaches were considered: 1. **Reflect API**: Instead of using the Proxy API, the benchmark could use the Reflect API to achieve similar results. 2. **Closure-based approach**: The benchmark could use a closure-based approach to wrap the unwrappable objects, eliminating the need for the Proxy API. However, these alternatives would likely introduce additional complexity and may not provide significant performance benefits over the existing approaches.
Related benchmarks:
Variable assignment from object | traditional vs destructuring
Spread vs Object.assign (modify ) vs Object.assign (new)
Optional chaining vs Empty method
Destructure from Object.seal vs Object.freeze vs normal(special edition)
new object vs new instance of new class
Comments
Confirm delete:
Do you really want to delete benchmark?