prtorpropr

JavaScript performance comparison

Test case created by Esailija

Preparation code

<script>
function Prop() {
    var val = 3;
    this.method1 = function(){};
    this.method2 = function(){};
    this.method3 = function(){};
    this.method4 = function(){};
    this.method5 = function(){};
    this.method6 = function(){};
    this.method7 = function(){};
    this.method8 = function(){};
    this.method9 = function(){};
    this.method10 = function(){};
    this.method11 = function(){};
    this.method12 = function(){};
    this.method13 = function(a){
        return val + a
    };
    this.method14 = function(){};
    this.method15 = function(){};
    this.method16 = function(){};
    this.method17 = function(){};
    this.method18 = function(){};
    this.method19 = function(){};
    this.method20 = function(){};
    this.method21 = function(){};
    this.method22 = function(){};
    this.method23 = function(){};
    this.method24 = function(){};
    this.method25 = function(){};
}

var Proto = (function() {

    function Proto() {
        this._val = 3;
    }
    var method = Proto.prototype;

    method.method1 = function(){};
    method.method2 = function(){};
    method.method3 = function(){};
    method.method4 = function(){};
    method.method5 = function(){};
    method.method6 = function(){};
    method.method7 = function(){};
    method.method8 = function(){};
    method.method9 = function(){};
    method.method10 = function(){};
    method.method11 = function(){};
    method.method12 = function(){};
    method.method13 = function(a){
        return this._val + a;
    };
    method.method14 = function(){};
    method.method15 = function(){};
    method.method16 = function(){};
    method.method17 = function(){};
    method.method18 = function(){};
    method.method19 = function(){};
    method.method20 = function(){};
    method.method21 = function(){};
    method.method22 = function(){};
    method.method23 = function(){};
    method.method24 = function(){};
    method.method25 = function(){};

    return Proto;
})();
</script>
<script>
Benchmark.prototype.setup = function() {
    var b = new Prop(),
    c = new Proto();
};

Benchmark.prototype.teardown = function() {
    console.log(a.method1());
};
</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
PropAllocation
var a = new Prop();
pending…
ProtoAllocation
var a = new Proto();
pending…
PropCall
if( b.method13(7) !== 10 ) die

var a = b
pending…
ProtoCall
if( c.method13(7) !== 10 ) die

var a = c
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