direct-vs-chain

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Point(x, y) {
      this.x = x;
      this.y = y;
      this.mask = 1;
    }
    Point.prototype.isPoint = true
    var p = new Point(0, 0);
   
    function PointManyInterfaces(x, y) {
      this.x = x;
      this.y = y;
    }
    PointManyInterfaces.prototype.isFoo0 = true;
    PointManyInterfaces.prototype.isFoo1 = true;
    PointManyInterfaces.prototype.isFoo2 = true;
    PointManyInterfaces.prototype.isFoo3 = true;
    PointManyInterfaces.prototype.isFoo4 = true;
    PointManyInterfaces.prototype.isFoo5 = true;
    PointManyInterfaces.prototype.isFoo6 = true;
    PointManyInterfaces.prototype.isFoo7 = true;
    PointManyInterfaces.prototype.isFoo9 = true;
    PointManyInterfaces.prototype.isFoo10 = true;
    PointManyInterfaces.prototype.isFoo11 = true;
    PointManyInterfaces.prototype.isFoo12 = true;
    PointManyInterfaces.prototype.isFoo13 = true;
    PointManyInterfaces.prototype.isFoo14 = true;
    PointManyInterfaces.prototype.isFoo15 = true;
    PointManyInterfaces.prototype.isFoo16 = true;
    PointManyInterfaces.prototype.isFoo17 = true;
    PointManyInterfaces.prototype.isFoo18 = true;
    PointManyInterfaces.prototype.isFoo19 = true;
    PointManyInterfaces.prototype.isFoo20 = true;
    PointManyInterfaces.prototype.isFoo21 = true;
    PointManyInterfaces.prototype.isFoo22 = true;
    PointManyInterfaces.prototype.isFoo23 = true;
    PointManyInterfaces.prototype.isFoo24 = true;
    PointManyInterfaces.prototype.isFoo25 = true;
    PointManyInterfaces.prototype.isFoo26 = true;
    PointManyInterfaces.prototype.isFoo27 = true;
    PointManyInterfaces.prototype.isFoo28 = true;
    PointManyInterfaces.prototype.isFoo29 = true;
    PointManyInterfaces.prototype.isFoo30 = true;
    PointManyInterfaces.prototype.isFoo31 = true;
   
    var pis = new PointManyInterfaces(0, 0);
};
</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
direct property
var sum = 0
for(var i = 0; i < 1000; i++) {
  if(p.mask & 1) {
    sum = p.x + i;
  }
}
pending…
prototype chain
var sum = 0
for(var i = 0; i < 1000; i++) {
  if(p.isPoint) {
    sum = p.x + i;
  }
}
pending…
instanceof
var sum = 0
for(var i = 0; i < 1000; i++) {
  if(p instanceof Point) {
    sum = p.x + i;
  }
}
pending…
many interfaces
var sum = 0
for(var i = 0; i < 1000; i++) {
  if(p.isFoo31) {
    sum = p.x + i;
  }
}
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