Object.defineProperty vs class

Benchmark created on


Setup

class EphemeralRef {
	internal = '';
	get current() {
		return this.internal;
	}
	set current(value) {
		this.internal = value;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Class
const ephemeralRef = new EphemeralRef();
ready
Object.defineProperty
const ephemeralRef = { internal: '' };

Object.defineProperty(ephemeralRef, 'current', {
	get() {
		return ephemeralRef.internal;
	},
	set(value) {
		ephemeralRef.internal = value;
	},
});
ready

Revisions

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