Loops

JavaScript performance comparison

Revision 159 of this test case created by asdffwqegvwvsd

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/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++;
};
pending…
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++;
};
pending…
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];
};
pending…
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];
};
pending…
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--);
pending…
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];
};
pending…
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];
};
pending…
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];
};
pending…
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];
};
pending…
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];
};
pending…
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;
});
pending…
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);
pending…
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;
}
pending…
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;
}
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