Push vs [i]

Benchmark created by Simon Goellner 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

Revisions

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