for loop length cache

JavaScript performance comparison

Revision 5 of this test case created by Kyle Simpson

Preparation code

<script>
  var arr = new Array(10000),
      len = arr.length;
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
no cache
for (var i = 0; i < arr.length; i++) {
 var a = arr[i];
}
pending…
cache length
for (var i = 0; i < len; i++) {
 var a = arr[i];
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment