object = { value: 'data' };
proxy = new Proxy(object, {})
proxyWithHandler = new Proxy(object, {
get(target, prop, receiver) {
return target[prop]
}
})
object.value;
proxy.value
proxyWithHandler.value
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object access | |
Proxy access | |
Proxy with get handler access |
Test name | Executions per second |
---|---|
Object access | 186117904.0 Ops/sec |
Proxy access | 72197752.0 Ops/sec |
Proxy with get handler access | 53666948.0 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks.
Benchmark Definition
The provided JSON represents a benchmark that tests the performance of accessing an object value using different approaches: direct object access, proxy access without reflection, and proxy access with a getter handler. The objective is to measure which approach yields the best performance results.
Options Compared
There are three options being compared:
value
property of the object
directly.proxy
is created with an empty handler object {}
and then accessed like a normal object.proxyWithHandler
is created with a getter handler that returns the value of the corresponding property on the target object.Pros and Cons
Here's a brief analysis of each approach:
Library Usage
None of the benchmark tests use any external libraries. The code uses native JavaScript features to create proxies and access their properties.
Special JS Features/Syntax
The benchmark tests make use of the following special JavaScript features:
Other Considerations
When writing this benchmark, consider the following factors that might affect performance:
As for alternative approaches or testing scenarios, some possibilities include:
Object.create()
or Proxy
with a more efficient handler.Keep in mind that the specific choices made for this benchmark are likely aimed at isolating the impact of proxy access and getter handlers on performance.