Array index assign vs Array.push

Benchmark created on


Setup

  Array.prototype.mypush = function(element) {
    this[this.length] = element;
  };

Test runner

Ready to run.

Testing in
TestOps/sec
Array index assign
  let a = [];
  for (let i = 0; i < 10000; i++) {
  	a.mypush(i)
  }
ready
Array.push
  let a = [];
  for (let i = 0; i < 10000; i++) {
  	a.push(i)
  }
ready

Revisions

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