Performance of prototype inheritance

JavaScript performance comparison

Test case created by

Preparation code

<script>
  var BaseObj = {
    a: 0,
    f: function() {}
  }

  var DerivedObj = Object.create(BaseObj);

  var BaseClass = function() {
      this.a = 0;
      }
      
  BaseClass.prototype.f = function() {}

  var DerivedClass = function() {
      BaseClass.call(this);
      }
      
  DerivedClass.prototype = Object.create(BaseClass.prototype);
</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
Plain object
var x = {
  a: 0,
  f: function() {}
}
x.f();
pending…
Object prototyping
var x = Object.create(DerivedObj)
x.f()
pending…
Class prototyping
var x = new DerivedClass()
x.f()
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