array.length vs. cached (v17)

Revision 17 of this benchmark created on


Setup

var a = [];
    for (var i = 0; i < 100000; i++) {
      a.push(i);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
cached for i++
(function(a) {
  var k = 0;
  for (var i = 0, aLen = a.length; i < aLen; i++) {
    k = a[i];
  }
  return k;
})(a);
ready
cached for ++i
(function(a) {
  var k = 0;
  for (var i = 0, aLen = a.length; i < aLen; ++i) {
    k = a[i];
  }
  return k;
})(a);
ready
while forward
(function(a) {
  var k = 0,
    i = -1,
    aLen = a.length;
  while (++i < aLen) {
    k = a[i];
  }
  return k;
})(a);
ready
cached, do while
(function(a) {
  var k = 0,
    i = 0,
    aLen = a.length;
  do {
    k = a[i];
  } while (++i < aLen)
  return k;
})(a);
ready

Revisions

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