Array direct assignment vs push (v20)

Revision 20 of this benchmark created by vincent piel on


Setup

var array = [];
    var array2 = [];
    array2.len = 0;
    var other_array = 0 ;
    var count = 100;
    var array_push = function (arr, item) {
       arr[arr.length] = item;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Direct assignment
for(var i = 0; i < count; i++)
{
  array[i] = i;
}
array[count] = (count = count + 200);
count = count % 200;
ready
Push
for(var i = 0; i < count; i++)
{
  array.push(i);
}
array[count] = (count = count + 200);
count = count % 200;
ready
Direct assignment (calculated)
for(var i = 0; i < count; i++)
{
  array[array.length] = i;
}
array[count] = (count = count + 200);
count = count % 200;
ready
other
for(var i = 0; i < count; i++)
{
  array[other_array++] = i;
}
array[count] = (count = count + 200);
count = count % 200;
ready
array2.len
for(var i = 0; i < count; i++)
{
  array2[array2.len++] =i;
}
array[count] = (count = count + 200);
count = count % 200;
ready
Direct assignment via function
for (var i = 0; i < count; ++i) {
   array_push(array2,i);
}
array[count] = (count = count + 200);
count = count % 200;
ready

Revisions

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