prop-vs-bit-call

JavaScript performance comparison

Revision 8 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function Point(x, y) {
    this.x = x;
    this.y = y;
    this.mask = 1;
  }
  Point.prototype.isPoint = true
  Point.prototype.addToX = function(n) {
    return this.x+n;
  }
  var p = new Point(0, 0);
  
  function PointManyInterfaces(x, y) {
    this.x = x;
    this.y = y;
    this.mask = 1;
  }
  PointManyInterfaces.prototype.addToX = function(n) {
    return this.x+n;
  }
  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;
  PointManyInterfaces.prototype.isPoint = true;
  
  var pis = new PointManyInterfaces(0, 0);
  
  function addToXProp(p, n) {
    if(p.addToX) {
      return p.addToX(n);
    }
  }
  
  function addToXBit(p, n) {
    if(p.mask & 1) {
      return p.addToX(n);
    }
  }

};
</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
property
var sum = 0
for(var i = 0; i < 1000; i++) {
  sum = addToXProp(p, i);
}
pending…
property many interfaces
var sum = 0
for(var i = 0; i < 1000; i++) {
  sum = addToXProp(pis, i);
}
pending…
bit
var sum = 0
for(var i = 0; i < 1000; i++) {
  sum = addToXBit(p, i);
}
pending…
bit many interfaces
var sum = 0
for(var i = 0; i < 1000; i++) {
  sum = addToXBit(p, 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.

0 Comments