native loop

JavaScript performance comparison

Revision 4 of this test case created by Maxime Warnier

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
      var array_test_length = 10000;
      var myTable = [];
      for (var i = 0; i <= array_test_length; i++) {
        myTable.push({
          id: i,
          data: i.toString()
        });
      }
      var ElementId = array_test_length / 2;

};
</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
for
for (var i = 0; i <= myTable.length; i++) {
  if (myTable[i].id === ElementId) {
    break;
  }
}
pending…
cached for loop
for (var i = 0,t = myTable.length;i<=t;i++) {
  if (myTable[i].id === ElementId) {
    break;
  }
}
pending…
for i++ equality
for (var i = 0,t = myTable.length;i!==t;i++) {
  if (myTable[i].id === ElementId) {
    break;
  }
}
pending…
cached for ++i equality
for (var i = 0,t = myTable.length;i!==t;++i) {
  if (myTable[i].id === ElementId) {
    break;
  }
}
pending…
reversed for
for (var i = myTable.length - 1; i >= 0; i--) {
  if (myTable[i].id === ElementId) {
    break;
  }
};
pending…
reversed for equality
for (var i = myTable.length - 1; i !== 0; i--) {
  if (myTable[i].id === ElementId) {
    break;
  }
};
pending…
while
var i = 0 ;
while (myTable[i].id !== ElementId && i <= myTable.length) {
  i++
}
pending…
while cached
var i = 0 ;
var t = myTable.length ;
while (myTable[i].id !== ElementId && i <= t) {
  i++
}
pending…
while cached equality
var i = 0 ;
var t = myTable.length ;
while (myTable[i].id !== ElementId && i !== t) {
  i++
}
pending…
reversed for simple equality
for (var i = myTable.length - 1; i != 0; i--) {
  if (myTable[i].id === ElementId) {
    break;
  }
};
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