Push vs [i] (v13)

Revision 13 of this benchmark created on


Description

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

Setup

var array = [];
    var count = 5000;

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
[i]
for( var i = 0; i < count; i++ ) {

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

}
ready
[i] inline
for( var i = 0; i < count; i++ ) {

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

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

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

}
ready

Revisions

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