array.length vs. cached

JavaScript performance comparison

Revision 36 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; a = a.concat(a, a, a, a, a, a, a, a);

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
cached, i++
(function(a) {
  var sum = 0;
  var aLen = a.length;
  for (var i = 0; i < aLen; i++) {
    sum += a[i];
  }
  return sum;
})(a);
pending…
cached, i+=1
(function(a) {
  var sum = 0;
  var aLen = a.length;
  for (var i = 0; i < aLen; i+=1) {
    sum += a[i];
  }
  return sum;
})(a);
pending…
cached
(function(a) {
  var sum = 0;
  var aLen = a.length;
  for (var i = 0; i < aLen; ++i) {
    sum += a[i];
  }
  return sum;
})(a);
pending…
not-cached
(function(a) {
  var sum = 0;
  for (var i = 0; i < a.length; ++i) {
    sum += a[i];
  }
  return sum;
})(a);
pending…

Compare results of other browsers

Revisions

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

0 Comments