Array Performance (v16)

Revision 16 of this benchmark created on


Description

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

Setup

var a1 = [{id: 1524288, name: 'name1'}, {id: 1524289, name: 'name1'}];

Test runner

Ready to run.

Testing in
TestOps/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];
}
 
ready
dynamic length
var id = 4524288;
for (var i = 0; i < a1.length; i++) {
  if (a1[i].id = id) result = a1[i];
}
 
ready
Smaller size fixed
var id = 524288;
var arraySize = a1.length;
for (var i = 0; i < arraySize; i++) {
  if (a1[i].id = id) result = a1[i];
}
 
ready
Smaller size dynamic
var id = 524288;
for (var i = 0; i < a1.length; i++) {
  if (a1[i].id = id) result = a1[i];
}
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.