Proxy Performance

Benchmark created on


Description

Compare proxies to direct access, getter/setter functions, and properties.

Setup

var testDirect = { x: 0 };
var testGetter = () => testDirect.x;
var testSetter = (x) => testDirect.x = x;
var testProperty = {};
var testPropertyX = 0;
Object.defineProperty(testProperty, "x", { get: () => testPropertyX, set: (x) => testPropertyX = x });
var testProxy = new Proxy({ x: 0 }, {
	get(target, prop, receiver) {
		return prop === "x" ? target.x : undefined;
	},
	set(target, prop, value, receiver) {
		if (prop === "x") {
			target.x = value;
			return true;
		} else {
			return false;
		}
	}
});

Test runner

Ready to run.

Testing in
TestOps/sec
Direct
testDirect.x = testDirect.x + 1
ready
Getter/Setter
testSetter(testGetter() + 1)
ready
Property
testProperty.x = testProperty.x + 1
ready
Proxy
testProxy.x = testProxy.x + 1
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.