backwards while vs modified for

JavaScript performance comparison

Test case created by Josh Rhoades and last updated

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
modified for
var arrTest1 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
  l = arrTest1.length,
  i, elem;
for (; i < l; i++) {
  elem = arrTest1[i];
  console.log('test1', elem);
}
pending…
backwards while
var arrTest2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
  l = arrTest2.length,
  elem;
while (l--) {
  elem = arrTest2[l];
  console.log('test2', elem);
}
pending…
regular for
var arrTest3 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
  l = arrTest3.length,
  elem;
for (var i = 0; i < l; i++) {
  elem = arrTest3[i];
  console.log('test3', elem);
}
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