Push vs [i] (v12)

Revision 12 of this benchmark created by Nindaff on


Description

is array.push(x) fast than array[i] = x ?

Setup

var array = [];
    var count = 5000;
    var _arr = new Array(count);

Test runner

Ready to run.

Testing in
TestOps/sec
Inline Push
for( var i = 0; i < count; i++ ) {

array.push({
  x: i,
  y: i
});

}
ready
Push
for( var i = 0; i < count; i++ ) {

var item = {
  x: i,
  y: i
};
array.push( item );

}
ready
Initialized length Array
for( var i = 0; i < count; i++ ) {

var item = {
  x: i,
  y: i
};
_arr[i] = item;

}
ready
Assign by index
for( var i = 0; i < count; i++ ) {

var item = {
  x: i,
  y: i
};
array[i] = item;

}
ready

Revisions

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