Array direct assignment vs push (v66)

Revision 66 of this benchmark created by Emanuel Jackstare on


Setup

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
var array = [];
for(var i = 0; i < count; i++)
{
  array[i] = Math.random();
}
array[count] = (count = count + 200);
count = count % 200;
ready
Push
var array = [];
for(var i = 0; i < count; i++)
{
  array.push(Math.random());
}
array[count] = (count = count + 200);
count = count % 200;
ready
Direct assignment (calculated)
var array = [];
for(var i = 0; i < count; i++)
{
  array[array.length] = Math.random();
}
array[count] = (count = count + 200);
count = count % 200;
ready
other
var array = [];
for(var i = 0; i < count; i++)
{
  array[other_array++] = Math.random();
}
array[count] = (count = count + 200);
count = count % 200;
ready
array2.len
var array = [];
for(var i = 0; i < count; i++)
{
  array2[array2.len++] = Math.random();
}
array[count] = (count = count + 200);
count = count % 200;
ready
Direct assignment via function
var array = [];
for (var i = 0; i < count; ++i) {
   array_push(array2, Math.random());
}
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.