getter vs function get (v2)

Revision 2 of this benchmark created on


Description

are getters really slower than just calling another function ? getters are so convenient but not if they kill 10x performance

Setup

const O = { a: 1, b: 2 }
O.getValue = function () { return this.a + this.b }
Object.defineProperty( O, `value`, {
    get: O.getValue
} )

Test runner

Ready to run.

Testing in
TestOps/sec
getter
O.value
ready
function get
O.getValue()
ready
direct
O.a + O.b
ready

Revisions

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