object = { value: 'data', getData() {return this.value;} };
Object.defineProperty(object, 'dataProperty', {
get() { return this.value; }
});
proxy = new Proxy(object, {})
proxyWithHandler = new Proxy(object, {
get(target, prop, receiver) {
return Reflect.get(target, prop, receiver)
}
})
object.value;
proxy.value
proxyWithHandler.value
object.getData();
object.dataProperty;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object access | |
Proxy access | |
Proxy with get handler access | |
Use of simple getter | |
Use of defineProperty |
Test name | Executions per second |
---|---|
Object access | 171215168.0 Ops/sec |
Proxy access | 61909836.0 Ops/sec |
Proxy with get handler access | 35833148.0 Ops/sec |
Use of simple getter | 168935952.0 Ops/sec |
Use of defineProperty | 145686752.0 Ops/sec |
Let's break down what's being tested in the provided JSON.
Benchmark Definition
The benchmark defines two objects: object
and proxy
. The script preparation code creates these objects, including setting up a getter for dataProperty
on object
using defineProperty
, and creating a proxy for object
using Proxy
.
Options Being Compared
There are four options being compared:
value
property directly on object
.value
property through the proxy created for object
.value
property through a proxy that uses a getter function to retrieve its value.getData()
method on object
to retrieve its value.Pros and Cons
Here's a brief overview of each option:
value
property, but it may not be as efficient as other options since it involves a simple lookup.value
property is accessed and retrieved.value
property through the proxy.getData()
method on object
is an alternative way to retrieve its value.Library Used
None explicitly mentioned in this benchmark.
Special JS Feature/Syntax
This benchmark does not use any special JavaScript features or syntax that would require additional explanation.
Other Considerations
The benchmark is designed to compare the performance of different ways to access and retrieve data from an object. The results will likely indicate which approach is most efficient, depending on the specific use case and requirements.
As for alternatives, other options might include:
dataProperty
directly on the proxy.However, without additional context or requirements, these alternatives are not relevant to this specific benchmark.