JS loop comparison

Benchmark created by shprink on


Setup

var arr = new Array(100);

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
cached while loop
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
for loop
for (var i = 0; i < arr.length; ++i) {
  arr[i];
};
ready
cached for loop
var i = 0,
  len = arr.length
for (; i < len; ++i) {
  arr[i];
};
ready
Reverse for loop
for (var i = arr.length; i--;) {
  arr[i];
};
ready

Revisions

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

  • Revision 1: published by shprink on
  • Revision 2: published by shprink on
  • Revision 3: published by shprink on
  • Revision 4: published by Daniel Joppi on
  • Revision 6: published by Benjamin Reed on