Super Calls

JavaScript performance comparison

Test case created by Sebastian Markbåge

Preparation code

<script>
  var Parent = function(z) {
   this.x = 1;
   this.y = z;
  };
  
  Parent.prototype.method = function(n) {
   this.y += n + 1;
  };
  
  function empty() {};
  
  var object = function(inherits) {
   empty.prototype = inherits.prototype;
   return new empty();
  };
  
  // Closure Call Indirect
  var base = Parent.prototype;
  
  var ClassA = function(z) {
   Parent.call(this, z);
  };
  
  ClassA.prototype = object(Parent);
  
  ClassA.prototype.method = function(n) {
   base.method.call(this, n + 1);
  };
  
  // Closure Call Direct
  var baseMethod = Parent.prototype.method;
  
  var ClassB = function(z) {
   Parent.call(this, z);
  };
  
  ClassB.prototype = object(Parent);
  
  ClassB.prototype.method = function(n) {
   baseMethod.call(this, n + 1);
  };
  
  // Prototype Invoke
  var ClassC = function(z) {
   this.ParentConstructor(z);
  };
  
  ClassC.prototype = object(Parent);
  
  ClassC.prototype.ParentConstructor = Parent;
  ClassC.prototype.ParentMethod = Parent.prototype.method;
  
  ClassC.prototype.method = function(n) {
   this.ParentMethod(n + 1);
  };
  
  // Prototype Call
  var ClassD = function(z) {
   this.baseConstructor(z);
  };
  
  ClassD.prototype = object(Parent);
  
  ClassD.prototype.baseConstructor = Parent;
  ClassD.prototype.base = Parent.prototype;
  
  ClassD.prototype.method = function(n) {
   this.base.method.call(this, n + 1);
  };
  
  var a = new ClassA(2);
  var b = new ClassB(2);
  var c = new ClassC(2);
  var d = new ClassD(2);
</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
Prototype Call
d.method(3);
pending…
Closure Call Direct
b.method(3);
pending…
Closure Call Indirect
a.method(3);
pending…
Prototype Invoke
c.method(3);
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