getters setters performance

Benchmark created on


Setup

class Foo {
	_a = 0
	
	set a(val) {
		this._a = val
	}
	
	get a() {
		return this._a
	}
}

class ClassWithoutAccessors {
	a = 0
	
	setA(val) {
		this.a = val
	}
}

const state = {
	a: 0
}

const bar = {
	set a(val) {
		state.a = val
	},
	get b() {
		return state.a
	}
}

const foo = new Foo()
const noAccessors = new ClassWithoutAccessors()

Test runner

Ready to run.

Testing in
TestOps/sec
Class getters
foo.a
ready
Class setters
foo.a += 1
ready
Obj getters
bar.a
ready
Obj setters
bar.a += 1
ready
get: Class without accessors
noAccessors.a
ready
set: Class without accessors
noAccessors.a += 1
ready

Revisions

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