ES5 getters/setters versus getter/setter methods

JavaScript performance comparison

Revision 15 of this test case created by

Preparation code

<script>
var obj = {
    _prop : 0,

    prop : {
        get : function () {},
        set : function (value) {}
    },
    getProp : function () {},
    setProp : function(value) {},

    value : {
        get : function () {
            return this._prop;
        },
        set : function (value) {
            this._prop = value;
        }
    },
    getValue : function () {
        return this._prop
    },
    setValue : function (value) {
        this._prop = value; 
    }
};
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Alternative - Get Values
obj.getValue();
pending…
es5 - Set Value
obj.value = 0;
pending…
Alternative - Set Values
obj.setValue(0);
pending…
ES5 - Access Only
obj.prop;
obj.prop = 0;
pending…
Alternative - Access Only
obj.getProp();
obj.setProp(0);
pending…
es5 - Get Value
obj.value;
pending…

Compare results of other browsers

Revisions

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

0 Comments