Loops (v55)

Revision 55 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  var arr = new Array(100);
function foo(x) {
  x;
};

for (var j = 0 ; j<100 ; j++){
arr[j] = {name: 'Irvin', age: 24, sex: 'gay'};
}


if(!Array.prototype.forEach){
    Array.prototype.forEach= function(action, that /*opt*/) {
        for (var i= 0, n= this.length; i<n; i++)
           if(i in this)
           action.call(that, this[i], i, this);
    };
}


</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
Reverse while loop
var i = arr.length;
while (i--) {
  arr[i];
};
ready
Reverse for loop
for (var i = arr.length; 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, caching the length
for (var i = -1, len = arr.length; ++i < len;) {
  arr[i];
};
ready
Native Array#forEach implementation
arr.forEach(function(x) {
  x;
});
ready
Native Array#forEach implementation with named function
arr.forEach(foo);
ready

Revisions

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