Array Performance

JavaScript performance comparison

Revision 17 of this test case created


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

Preparation code

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


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

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment