Method calling with inheritance test

JavaScript performance comparison

Test case created by Andy Appleton

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  // Setup
  var CloParent,  CloChild1,  CloChild2,  cloInstance,
      ProtParent, ProtChild1, ProtChild2, protInstance;
  
  // Define parent class
  CloParent = function(arg1){
    var self = {
      getArg1:function(){
        return arg1;
      }
    };
    return self;
  };
  
  // Define first level descendant class
  CloChild1 = function(arg1, arg2){
    var self = new CloParent(arg1);
    self.getArg2 = function(){
      return arg2;
    };
    return self;
  };
  
  // Define second level descendant class
  CloChild2 = function(arg1, arg2, arg3){
    var self = new CloChild1(arg1, arg2);
    self.getArg3 = function(){
      return arg3;
    };
    return self;
  };
  cloInstance = new CloChild2('arg1 contents', 'arg2 contents', 'arg3 contents');
  
  
  // Define parent class
  ProtParent = function(arg1){
    this.arg1 = arg1;
  };
  ProtParent.prototype.getArg1 = function(){
    return this.arg1;
  };
  
  // Define first level descendant class
  ProtChild1 = function(arg1, arg2){
    this.arg1 = arg1;
    this.arg2 = arg2;
  };
  ProtChild1.prototype = new ProtParent(this.arg1);
  ProtChild1.prototype.getArg2 = function(){
    return this.arg2;
  };
  
  // Define second level descendant class
  ProtChild2 = function(arg1, arg2, arg3){
    this.arg1 = arg1;
    this.arg2 = arg2;
    this.arg3 = arg3;
  };
  ProtChild2.prototype = new ProtChild1(this.arg1, this.arg2);
  ProtChild2.prototype.getArg3 = function(){
    return this.arg3;
  };
  protInstance = new ProtChild2('arg1 contents', 'arg2 contents', 'arg3 contents');
  

};

Benchmark.prototype.teardown = function() {
  delete cloInstance;
  delete protInstance;

};
</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
Closure parent method
cloInstance.getArg1();
pending…
Closure child 1 method
cloInstance.getArg2();
pending…
Closure child 2 method
cloInstance.getArg3();
pending…
Prototype parent method
protInstance.getArg1();
pending…
Prototype child 1 method
protInstance.getArg2();
pending…
Prototype child 2 method
protInstance.getArg2();
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