While vs For Queue (v42)

Revision 42 of this benchmark created by Scott Koon on


Description

Adding in manual hoisting for the length of the array to see if that makes a difference.

Setup

var items = [], total = 0, i = 0, j = 0;
    for(;i<100000;i++) {
      items[i] = Math.ceil( Math.random() * 10 );
    }

Test runner

Ready to run.

Testing in
TestOps/sec
For
for(; j<items.length; j++) {
  total += items[j];
}
ready
While
while(items.length) {
  total += items.shift();
}
ready
Do
do {
  total += items.shift();
} while(items.length);
ready
For(hoisted)
var l = items.length;
for(; j<l; j++) {
  total += items[j];
}
ready

Revisions

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