Loops (v121)

Revision 121 of this benchmark created by Visha on


Setup

var arr = [];
    for (var i = 0; i < 1000; i++) {
      arr.push(i);
    }
    var arrLen = arr.length;

Test runner

Ready to run.

Testing in
TestOps/sec
While Loop (uncached)
var i = 0;
while (i < arr.length) {
  arr[i] += 1;
  i++;
};
ready
While Loop (cached)
var i = 0;
while (i < arrLen) {
  arr[i] += 1;
  i++;
};
ready
While Loop (reversed)
var i = arr.length;
while (i--) {
  arr[i] += 1;
};
ready
While Loop (reversed, postprocessed)
var i = arr.length;
while (i-- > 0) {
  arr[i] += 1;
};
ready
Do-While Loop (reversed)
var i = arr.length;
do {
  arr[i] += 1;
} while (i--);
ready
For Loop (reversed)
for (var i = arr.length; i--;) {
  arr[i] += 1;
};
ready
For Loop (uncached, proprocessed)
for (var i = 0; i < arr.length; ++i) {
  arr[i] += 1;
};
ready
For Loop (cached, proprocessed)
for (var i = 0; i < arrLen; ++i) {
  arr[i] += 1;
};
ready
For Loop (uncached, proprocessed)
for (var i = -1; ++i < arr.length;) {
  arr[i] += 1;
};
ready
For Loop (cached, proprocessed)
for (var i = -1; ++i < arrLen;) {
  arr[i] += 1;
};
ready
Foreach (native function)
arr.forEach(function(x) {
  x += 1;
});
ready
Foreach (function call)
function foo(x) {
  x += 1;
};
arr.forEach(foo);
ready
For Loop (uncached) Simple
var i;
for (i = 0; i < arr.length; i += 1) {
  arr[i] += 1;
}
ready
For Loop (cached) Simple
var i;
for (i = 0; i < arrLen; i += 1) {
  arr[i] += 1;
}
ready
Special For Loop (reversed, cached)
for (var i = arrLen; i--;) {
  arr[i] += 1;
};
ready

Revisions

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