Loops (v159)

Revision 159 of this benchmark created by asdffwqegvwvsd on


Test runner

Ready to run.

Testing in
TestOps/sec
while loop that imitates a for loop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
var i = 0;
while (i < arr.length) {
 arr[i];
 i++;
};
ready
while loop that imitates a for loop, caching the length
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
var i = 0,
    len = arr.length;
while (i < len) {
 arr[i];
 i++;
};
ready
Reverse while loop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
var i = arr.length;
while (i--) {
 arr[i];
};
ready
Reverse while loop without implicit ToBoolean
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
var i = arr.length;
while (i-- > 0) {
 arr[i];
};
ready
Reverse do … while loop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
var i = arr.length;
do {
 arr[i];
} while (i--);
ready
Reverse for loop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
for (var i = arr.length; i--;) {
 arr[i];
};
ready
Old ’n’ busted for loop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
for (var i = 0; i < arr.length; ++i) {
 arr[i];
};
ready
Old ’n’ busted for loop, caching the length
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
for (var i = 0, len = arr.length; i < len; ++i) {
 arr[i];
};
ready
Cool guy loop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
for (var i = -1; ++i < arr.length;) {
 arr[i];
};
ready
Cool guy loop, caching the length
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
for (var i = -1, len = arr.length; ++i < len;) {
 arr[i];
};
ready
Native Array#forEach implementation
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
arr.forEach(function(x) {
 x;
});
ready
Native Array#forEach implementation with named function
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5];
function foo(x) {
 x;
};
arr.forEach(foo);
ready
shift
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5], val;
while(val = arr.shift()) {
    val;
}
ready
pop
var arr = [61,56,7,64,6927,62,80,44,3445,29,42,79,9225,52,27,74,9151,58,71,2,1872,60,35,27,1124,7,46,94,2435,33,58,67,1935,59,52,19,9041,44,58,32,419,89,83,74,6981,99,82,89,6937,43,51,88,848,61,24,10,93100,77,83,48,9850,95,35,95,9068,87,27,47,6195,32,28,66,736,92,32,16,7416,69,91,2,5], val;
while(val = arr.pop()) {
    val;
}
ready

Revisions

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