object = { value: 'data' };
proxy = new Proxy(object, {})
getProxyWithHandler = () => new Proxy(object, {
get(target, prop, receiver) {
return Reflect.get(target, prop, receiver)
}
})
proxyWithHandler = getProxyWithHandler()
object.value;
proxy.value
proxyWithHandler.value
getProxyWithHandler().value
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Object access | |
Proxy access | |
Proxy with get handler access | |
New Proxy with handler |
Test name | Executions per second |
---|---|
Object access | 15666077.0 Ops/sec |
Proxy access | 14982360.0 Ops/sec |
Proxy with get handler access | 6009883.5 Ops/sec |
New Proxy with handler | 3119687.0 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks.
Benchmark Overview
The provided JSON represents a benchmark that tests the performance of accessing different types of proxies in JavaScript: traditional objects, new Proxy instances, and proxy instances with a custom get handler.
Options Compared
The benchmark compares four options:
value
property of the object
variable.value
property of the proxy
instance.value
property of the proxyWithHandler
instance, which has a custom get handler function.new Proxy()
constructor and accessing its value
property.Pros and Cons
Here's a brief summary of the pros and cons of each approach:
Library Used
None, as this benchmark doesn't rely on any external libraries.
Special JS Feature/Syntax
This benchmark uses a feature introduced in ECMAScript 2011 (ES5.1): Reflect.get()
. This method is used to implement the custom get handler function in the Proxy with Get Handler Access scenario.
Other Considerations
When writing benchmarks like this, it's essential to consider factors such as:
Keep in mind that benchmarking is an art and a science. The results may vary depending on the specific use case and environment.
As for alternatives, if you're interested in exploring other approaches or libraries, here are a few options:
Feel free to ask if you'd like me to elaborate on any of these points!