While vs For Queue vs jq.each (v58)

Revision 58 of this benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

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
jquery.each
$.each(items, function(index, item) {
  total += item;
});
ready
normal while
var i = items.length;
while (i > 0) {
  total += items[i - 1];
  i--;
}
ready
jquery each 2
$(items).each(function(index, item) {
  total += item;
});
ready
var i = items.length;
while (i--) {
  total += items[i];
}
ready

Revisions

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