Private vs Public property accessing speed (v23)

Revision 23 of this benchmark created on


Setup

class CPrivate {
	#pri0 = 0
	#pri1 = 1
	#pri2 = 2
	#pri3 = 3
	#pri4 = 4
	#pri5 = 5
	#pri6 = 6
	#pri7 = 7
	#pri8 = 8
	#pri9 = 9

	sum() {
		this.#pri0++
		
		return this.#pri0 + this.#pri1 + this.#pri2 + this.#pri3 + this.#pri4 + this.#pri5 + this.#pri6 + this.#pri7 + this.#pri8 + this.#pri9
	}
}

class CPublic {
	pub0 = 0
	pub1 = 1
	pub2 = 2
	pub3 = 3
	pub4 = 4
	pub5 = 5
	pub6 = 6
	pub7 = 7
	pub8 = 8
	pub9 = 9

	sum() {
		this.pub0++
		
		return this.pub0 + this.pub1 + this.pub2 + this.pub3 + this.pub4 + this.pub5 + this.pub6 + this.pub7 + this.pub8 + this.pub9

	}
}

class CConstructor {
	constructor() {
		this.pub0 = 0
		this.pub1 = 1
		this.pub2 = 2
		this.pub3 = 3
		this.pub4 = 4
		this.pub5 = 5
		this.pub6 = 6
		this.pub7 = 7
		this.pub8 = 8
		this.pub9 = 9
	}

	sum() {
		this.pub0++

		return this.pub0 + this.pub1 + this.pub2 + this.pub3 + this.pub4 + this.pub5 + this.pub6 + this.pub7 + this.pub8 + this.pub9
	}
}

var c_private = new CPrivate();
var c_public = new CPublic();
var c_constructor = new CConstructor();

var output

Test runner

Ready to run.

Testing in
TestOps/sec
private field
output += c_private.sum();

ready
public field
output += c_public.sum();

ready
pub in constructor
output += c_constructor.sum();

ready

Revisions

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