declaration apply vs prototype reference vs super

JavaScript performance comparison

Revision 2 of this test case created by tomalec

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Parent(){this.a = 1;}
    Parent.prototype.method = function(){return this.a;}
   
    function Child(){this.a=1;this.b=2;}
   
    Child.prototype = new Parent();
    Child.prototype.parent = Parent.prototype;
};
</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
Prototype ref
Child.prototype._method = Parent.prototype.method;
Child.prototype.method = function(){
 return this._method +1;
}
pending…
Apply
Child.prototype.method = function(){
 return Parent.prototype.method.apply(this,arguments) +1;
}
pending…
Super
Child.prototype.method = function(){
 return this.parent.method.apply(this,arguments) +1;
}
pending…
Call
Child.prototype.method = function(arg){
 return Parent.prototype.method.call(this,arg) +1;
}
pending…
Call super
Child.prototype.method = function(arg){
 return this.parent.method.call(this,arg) +1;
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment