object = { value: 'data' };
proxy = new Proxy(object, {})
proxyWithHandler = new Proxy(object, {
get(target, prop, receiver) {
return 'data'
}
})
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 | 113220512.0 Ops/sec |
Proxy access | 48734292.0 Ops/sec |
Proxy with get handler access | 35319184.0 Ops/sec |
I'd be happy to help you understand the benchmark being tested on MeasureThat.net.
What is tested?
The benchmark measures the performance difference between accessing an object's property directly (object.value
) versus using a proxy object with a getter handler (proxyWithHandler.value
). In this case, both proxy
and proxyWithHandler
point to the same underlying object (object
).
Options compared:
There are three options being compared:
object.value
proxy.value
proxyWithHandler.value
Pros and Cons of each approach:
Other considerations:
Proxy
object with an empty handler ({}
) implies that no custom behavior is being applied. However, if you were to create a more complex getter handler, it could potentially introduce additional overhead.Library/Functionality used:
In this benchmark, no external libraries or functions are explicitly mentioned. However, the use of Proxy
objects is a built-in JavaScript feature since ES6 (ECMAScript 2015).
There is no mention of any special JavaScript features or syntax being used in this benchmark.
Alternatives:
If you're interested in exploring similar benchmarks, MeasureThat.net has many other tests that compare different JavaScript scenarios, such as:
new Date()
vs. using a timestamp to represent time elapsedKeep in mind that benchmark results can vary depending on specific use cases, platforms, and browser versions. It's always interesting to see how different approaches compare under various conditions.