function multiInherit (p1,p2) {
return Object.create(new Proxy(Object.create(null), {
get (target, prop, receiver) {
return p1[prop] || p2[prop]
}
}));
}
var o1 = {value:1}
var o2 = {value2:2}
var obj = multiInherit(o1, o2);
o1.value;
o2.value
obj.value2
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
o1 | |
o2 | |
Proxy |
Test name | Executions per second |
---|---|
o1 | 28827338.0 Ops/sec |
o2 | 28422342.0 Ops/sec |
Proxy | 20456202.0 Ops/sec |
Let's break down the provided benchmark and explain what it tests, along with the pros and cons of different approaches.
Benchmark Overview
The benchmark is designed to test the performance of getting properties from an object created using JavaScript's Proxy mechanism, specifically in a scenario where multiple inheritance is used. The benchmark defines a function multiInherit
that creates a new proxy object by combining two existing objects (o1
and o2
) using the Object.create(new Proxy(...))
syntax.
Test Cases
There are three test cases:
o1.value;
o2.value;
obj.value2;
These test cases are designed to measure the performance of getting properties from the created proxy object (obj
) in each of these scenarios:
o1
or o2
.obj
.Library and Features
The benchmark uses the following library and feature:
Approaches and Performance Considerations
There are two primary approaches to implementing this benchmark:
o1
or o2
, which is the most straightforward approach.obj
, which introduces an extra layer of indirection.Other Alternatives
If you wanted to modify the benchmark to explore other approaches, here are a few options:
Proxy
mechanism, such as using Object.create(null)
instead of creating a new object.access-control
or implement your own custom access control mechanism.Keep in mind that modifying the benchmark should be done with caution, as it may affect its accuracy and relevance to real-world scenarios.