loops (v3)

Revision 3 of this benchmark created by Grzegorz on


Preparation HTML

<script>
  var ar = [1, 2, 3, 4, 5, 3, 2, 2, 3, 4, 5, 6, 7, 5, 4, 32, 3, 5, 6],
      sum = 0;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
typical
for (var i = 0; i < ar.length; i++) {
 sum += ar[i];
}
ready
length cached
var len = ar.length;
for (var i = 0; i < len; i++) {
 sum += ar[i];
}
ready
while loop
var len = ar.length,
    i = 0;
while (i < len) {
 sum += ar[i];
 i++;
}
ready
inversed while loop
var i = ar.length;
while (i--) {
 sum += ar[i];
}
ready

Revisions

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

  • Revision 3: published by Grzegorz on