Simple Inheritance

Benchmark created on


Description

Measure class performance (http://ejohn.org/blog/simple-javascript-inheritance/)

See http://jsperf.com/mootools-inheritance for mootools version.

Preparation HTML

<script src="//www.ckoehn.de/files/work/dcs/js/inheritance.js"></script>
<script>
 var Point = Class.extend({
  init: function() {
   this.x = 0;
   this.y = 0;
  },
 
  setX: function(value) {
   this.x = value;
  },
 
  setY: function(value) {
   this.y = value;
  }
 });
 
 
 var Point3D = Point.extend({
  init: function() {
   this._super();
   this.z = 0;
  },
 
  setX: function(value) {
   this._super(value);
   this.z = 3000;
  },
 
  setZ: function(value) {
   this.z = value;
  }
 });
 
 var p = new Point(),
     p3d = new Point3D();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Construct Class
p = new Point();
ready
Construct Subclass
p3d = new Point3D();
ready
Call Method on Class
p.setX(5);
ready
Call overridden Method on Subclass
p3d.setX(1);
ready
Call inherited Method on Subclass
p3d.setY(2);
ready
Call Method on Subclass
p3d.setZ(4);
ready

Revisions

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