Performance of prototype inheritance

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code

<script src="http://oopsjs.googlecode.com/files/oops.js"></script>
<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);

var OopsBase = function(){
	var _a;
	this.f = function(){
	} 
	this.init = function() {
		return this;
	}
};

var OopsDerived = function(){
	this.init = function(){
		_super.init();
		return this;	
	};
}.inherits(OopsBase);

</script>
    

Preparation code output

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() {}
}
pending…
Object prototyping
var x = Object.create(DerivedObj)
pending…
Class prototyping
var x = new DerivedClass()
pending…
Oops inheritance
var x = new OopsDerived().init();
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