Getter vs direct access

Benchmark created on


Setup

class Foo {

    constructor () {
        this.bar = 42;
    }

    getBar() {
        return this.bar
    }

}

foo = new Foo();

Test runner

Ready to run.

Testing in
TestOps/sec
Direct access
for (let i = 0; i < 10000; i++) {
    const a = foo.bar;
}
ready
Via getter
for (let i = 0; i < 10000; i++) {
	const a = foo.getBar();
}
ready

Revisions

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