ProtoInherit

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    if (typeof Object.create !== 'function') {    Object.create = function(o, props) {     function F() {}     F.prototype = o;        if (typeof(props) === "object") {      for (prop in props) {       if (props.hasOwnProperty((prop))) {        F[prop] = props[prop];       }      }     }     return new F();    };   }
};
</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
Proto
var inherits = function(ctor, superCtor) {
    ctor.super_ = superCtor;
    ctor.prototype = Object.create(superCtor.prototype, {
      constructor: {
        value: ctor,
        enumerable: false,
        writable: true,
        configurable: true
      }
    });
    };

function Base() {

}

var bProto = Base.prototype;

bProto.f1 = function() {};
bProto.f2 = function() {};
bProto.f3 = function() {};
bProto.f4 = function() {};

function Child() {}
inherits(Child, Base);
var cProto = Child.prototype;

cProto.f5 = function() {};
cProto.f6 = function() {};
cProto.f7 = function() {};
cProto.f8 = function() {};

var c = new Child();
c.f1();
c.f2();
c.f3();
c.f4();
c.f5();
c.f6();
c.f7();
c.f8();
pending…
inherits
function Base() {
  this.f1 = function() {};
  this.f2 = function() {};
  this.f3 = function() {};
  this.f4 = function() {};
}




function Child() {
  this.inheritFrom = Base;
  this.inheritFrom();

  this.f5 = function() {};
  this.f6 = function() {};
  this.f7 = function() {};
  this.f8 = function() {};
}

var c = new Child();
c.f1();
c.f2();
c.f3();
c.f4();
c.f5();
c.f6();
c.f7();
c.f8();
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