For Loop (v77)

Revision 77 of this benchmark created on


Preparation HTML

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
  var arr = new Array(25);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
while loop that imitates a for loop
var i = 0;
while (i < arr.length) {
  arr[i];
  i++;
};
ready
while loop that imitates a for loop, caching the length
var i = 0,
    len = arr.length;
while (i < len) {
  arr[i];
  i++;
};
ready
Reverse while loop
var i = arr.length;
while (i--) {
  arr[i];
};
ready
Reverse while loop without implicit ToBoolean
var i = arr.length;
while (i-- > 0) {
  arr[i];
};
ready
Reverse do … while loop
var i = arr.length;
do {
  arr[i];
} while (i--);
ready
Reverse for loop
var i= arr.length;
for (;i--;) {
  arr[i];
};
ready
Old ’n’ busted for loop
for (var i = 0; i < arr.length; ++i) {
  arr[i];
};
ready
Old ’n’ busted for loop, caching the length
for (var i = 0, len = arr.length; i < len; ++i) {
  arr[i];
};
ready
Cool guy loop
for (var i = -1; ++i < arr.length;) {
  arr[i];
};
ready
Cool guy loop, caching the length
var i = -1, len = arr.length;
for (; ++i < len;) {
  arr[i];
};
ready
Native Array#forEach implementation
arr.forEach(function(x) {
  arr[x];
});
ready
Native Array#forEach implementation with named function
function foo(x) {
  arr[x];
};
arr.forEach(foo);
ready
for Loop
for (var i = 0; i < arr.length; i++) {
  arr[i];
}
ready
cached for
var i, 
 l = arr.length;
for (i=0; i < l; i++) {
  arr[i];
}
ready
named jQuery each
var foo = function _foo(i, e) {
    e;
};
$.each(arr,foo);
ready
slice n pop
var item, list = arr.slice(0);
while (item = list.pop()) {
 item;
}
ready

Revisions

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