getter-setter-literals

JavaScript performance comparison

Test case created by mattdesl

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var Point = function() {
        this._literal = 0;
        this._defined = 0;
        this.property = 0;
    };
   
    Point.prototype = Object.create({
        get literal() {
                return this._literal;
        },
        set literal(x) {
                this._literal = x;
        }
    });
    Point.prototype.constructor = Point;
   
    Object.defineProperty(Point.prototype, "defined", {
        get: function() {
                return this._defined;
        },
        set: function(x) {
                this._defined = x;
        }
    });
   
    var points = [];
    for (var i=0; i<100; i++) {
        points.push( new Point() );
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
literal
for (var i=0; i<points.length; i++) {
    var p = points[i];
    p.literal += i;
}
pending…
defineProperty
for (var i=0; i<points.length; i++) {
    var p = points[i];
    p.defined += i;
}
pending…
property
for (var i=0; i<points.length; i++) {
    var p = points[i];
    p.property += i;
}
pending…

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

Compare results of other browsers

0 comments

Add a comment