Push vs [i] (v3)

Revision 3 of this benchmark created on


Description

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

Setup

var array = [];
    var count = 5000;
    
    var array2 = new Array(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
inline push 2
for( var i = 0; i < count; i++ ) {

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

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

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

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

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

}
ready

Revisions

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