array.length vs. cached (lhs)

Benchmark created by kazuho on


Setup

var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    a = a.concat(a, a, a, a, a, a, a, a);

Test runner

Ready to run.

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

Revisions

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