Private versus non-private property access

Benchmark created on


Description

Test native private property access versus non-private property access. Both are accessed through instance methods for fair comparison. Both properties are initialized with Math.random() to avoid optimization.

Setup

class Test {
	#priv = Math.random();
	pub = Math.random();
	
	getPriv() {
		return this.#priv;
	}
	getPub() {
		return this.pub;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Private access (through method)
const test = new Test();
const value = test.getPriv();
ready
Public access (through method)
const test = new Test();
const value = test.getPub();
ready

Revisions

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