Loops (v9)

Revision 9 of this benchmark created by JFSIII on


Preparation HTML

<script>
  var arr = [0.10682249767705798, 0.14486907375976443, 0.6462927060201764, 0.6292556400876492, 0.8099745651707053, 0.026500273030251265, 0.7382857352495193, 0.5344766841735691, 0.22327085630968213, 0.24449701607227325, 0.7350677938666195, 0.6318817269057035, 0.4497333753388375, 0.13978702807798982, 0.9937113982159644, 0.10464582103304565, 0.17325501330196857, 0.8751101894304156, 0.9214370618574321, 0.9315629999618977, 0.9574287028517574, 0.6804302292875946, 0.9841849545482546, 0.40987069346010685, 0.9036554736085236, 0.9259901174809784, 0.0500990585424006, 0.46978900488466024, 0.6059614983387291, 0.8904959128703922, 0.7805201290175319, 0.4566794545389712, 0.8901236969977617, 0.15785527019761503, 0.13910270063206553, 0.4444686050992459, 0.24656269908882678, 0.013628697721287608, 0.8823351296596229, 0.6517225778661668, 0.8656179755926132, 0.319807083113119, 0.9416418434120715, 0.4895877211820334, 0.7494010012596846, 0.46209143311716616, 0.12883754167705774, 0.9753151724580675, 0.35535205458290875, 0.3615832484792918, 0.16555020376108587, 0.14845219417475164, 0.6793364111799747, 0.9124694655183703, 0.12904104171320796, 0.5627066746819764, 0.4686171298380941, 0.45925762108527124, 0.047439801041036844, 0.05272998288273811, 0.9997752527706325, 0.5681999593507499, 0.03658395493403077, 0.473449117038399, 0.41875638091005385, 0.9229928401764482, 0.21255105710588396, 0.8998285585548729, 0.7891316991299391, 0.6155658783391118, 0.8909062976017594, 0.01669530081562698, 0.6303473026491702, 0.07017915393225849, 0.661483193282038, 0.8687872167211026, 0.09445122606121004, 0.7184298713691533, 0.675882583251223, 0.7469109978992492, 0.6185253721196204, 0.3029119106940925, 0.3411432655993849, 0.8031496377661824, 0.7103048702701926, 0.409196141641587, 0.9286595492158085, 0.48906754329800606, 0.5625964961946011, 0.72299401788041, 0.606512616854161, 0.3410133202560246, 0.8974989776033908, 0.5539657713379711, 0.6715649494435638, 0.013221136294305325, 0.8913248141761869, 0.9076709996443242, 0.12053222325630486, 0.3550975953694433];
</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 do … while loop
var i = arr.length;
do {
 arr[i];
} while (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
for (var i = -1; ++i < arr.length;) {
 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
function foo(x) {
 x;
};
arr.forEach(foo);
ready
Unrolled loop
for (var i = 0, len = arr.length; i < len; i = i + 10) {
 arr[i];
 arr[i + 1];
 arr[i + 2];
 arr[i + 3];
 arr[i + 4];
 arr[i + 5];
 arr[i + 6];
 arr[i + 7];
 arr[i + 8];
 arr[i + 9];
};
ready

Revisions

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