Loop Length Caching

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  var array_length = array.length;
  var obj = {length: array.length};

};
</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
No Caching
for ( var i = 1; i < array.length; i++) {
  i + 1;
}
pending…
With Caching
for ( var i = 1; i < array_length; i++) {
  i + 1;
}
pending…
Property access
for ( var i = 1; i < obj.length; i++) {
  i + 1;
}
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