array.length vs. cached

JavaScript performance comparison

Revision 17 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [];
  for (var i = 0; i < 100000; i++) {
    a.push(i);
  }

};
</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 for i++
(function(a) {
  var k = 0;
  for (var i = 0, aLen = a.length; i < aLen; i++) {
    k = a[i];
  }
  return k;
})(a);
pending…
cached for ++i
(function(a) {
  var k = 0;
  for (var i = 0, aLen = a.length; i < aLen; ++i) {
    k = a[i];
  }
  return k;
})(a);
pending…
while forward
(function(a) {
  var k = 0,
    i = -1,
    aLen = a.length;
  while (++i < aLen) {
    k = a[i];
  }
  return k;
})(a);
pending…
cached, do while
(function(a) {
  var k = 0,
    i = 0,
    aLen = a.length;
  do {
    k = a[i];
  } while (++i < aLen)
  return k;
})(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