Browser Diet - Cache Array Length - Inline vs. pre-loop variable definitions

JavaScript performance comparison

Revision 20 of this test case created by Adam

Info

Just to confirm my thoughts; that there's no difference here

Preparation code

<script>
  var arr = new Array(1000);
</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
Pre-loop var definition
var i, len;
for (i = 0, len = arr.length; i < len; i++) {
  // do something
}
pending…
Inline var definition
for (var i = 0, len = arr.length; i < len; i++) {
  // do something
}
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