Array Performance

JavaScript performance comparison

Revision 17 of this test case created

Info

Defining the length of the array before looping or after, which is faster?

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    var a1 = [{id: 4524288, name: 'name1'}, {id: 4524288, name: 'name1'}];

  };
</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
static length
var id = 4524288;
var arraySize = a1.length;
for (var i = 0; i < arraySize; i++) {
  if (a1[i].id = id) result = a1[i];
}
 
pending…
dynamic length
var id = 4524288;
for (var i = 0; i < a1.length; i++) {
  if (a1[i].id = id) result = a1[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