Push vs [i] (v7)

Revision 7 of this benchmark created on


Description

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

Setup

var array = [];
    var count = 10;

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
Array.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.