jhjhuubu

Benchmark created by rock on


Setup

var util = {inherits: function(ctor, superCtor) {
      ctor.super_ = superCtor;
      ctor.prototype = Object.create(superCtor.prototype, {
        constructor: {
          value: ctor,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
    }}
    
    function override(parent, fn) {
      fn.inherited = parent.prototype[fn.name];
      return fn;
    }
    
    function ParentClass1(par1, par2) {
      this.parentField1 = par1;
      this.parentField2 = par2;
    }
    
    ParentClass1.prototype.methodName = function(par) {
      this.parentField3 = par;
    };
    
    function ChildClass1(par1, par2) {
      this.constructor.super_.apply(this, arguments);
      this.childField1 = par1;
      this.childField2 = par2;
    }
    
    util.inherits(ChildClass1, ParentClass1);
    
    ChildClass1.prototype.methodName = override(ParentClass1, function methodName(par) {
      methodName.inherited.call(this, par);
      this.childField3 = par;
    });
     
    var _inherits = function (child, parent) {
      child.prototype = Object.create(parent && parent.prototype, {
        constructor: {
          value: child,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
      if (parent) child.__proto__ = parent;
    };
     
    var ParentClass2 = function ParentClass2(par1, par2) {
      this.parentField1 = par1;
      this.parentField2 = par2;
    };
     
    ParentClass2.prototype.methodName = function (par) {
      this.parentField3 = par;
    };
     
    var ChildClass2 = (function () {
      var _ParentClass2 = ParentClass2;
      var ChildClass2 = function ChildClass2(par1, par2) {
        _ParentClass2.call(this, par1, par2);
        this.childField1 = par1;
        this.childField2 = par2;
      };
     
      _inherits(ChildClass2, _ParentClass2);
     
      ChildClass2.prototype.methodName = function (par) {
        _ParentClass2.prototype.methodName.call(this, par);
        this.childField3 = par;
      };
     
      return ChildClass2;
    })();
    
    var inheritance6 = new ChildClass1('Lev', 'Nikolayevich');
    var _6to5 = new ChildClass2('Lev', 'Nikolayevich');
    
    var foo;

Test runner

Ready to run.

Testing in
TestOps/sec
inheritance6 instance
foo = new ChildClass1('Lev', 'Nikolayevich')
ready
6to5 instance
foo = new ChildClass2('Lev', 'Nikolayevich')
ready
inheritance6 method
foo = inheritance6.methodName('Tolstoy');
ready
6to5 method
foo = _6to5.methodName('Tolstoy');
ready

Revisions

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