Fastest array loops in Javascript (v469)

Revision 469 of this benchmark created on


Preparation HTML

<script>
  // Populate the base array
  var baseCount = 10000;
  var baseArr = new /*Array*/Uint16Array(baseCount);
  for (var i = 0; i < baseCount; i++) {
    baseArr[i] = i;
  }
  var len = baseArr.length;
  function someFn(ix) {
    return ix * 5 + 1 / 3 * 8;
  }
</script>

Setup

arr = baseArr /* baseArr.slice() */;

Test runner

Ready to run.

Testing in
TestOps/sec
Test1
var i = 0;

for (; i < len; i += 1) {
  someFn(arr[i]);
}
ready
Test2
var i;

for (i = 0; i < len; i += 1) {
  someFn(arr[i]);
}
ready
For loop, cached
ready
without length calculation
ready

Revisions

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