Cached Array Length Loop

JavaScript performance comparison

Test case created by Nathan

Preparation code

<script>
var array = [], setme;
for (var i = 0; i < 100; i++) {
    array.push(i);
}
</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
For Loop Cached Length
for (var len = array.length, j = 0; j < len; j++) setme = array[j]; 
pending…
For Loop No Cached Length
for (var k = 0; k < array.length; k++) setme = array[k]; 
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