push vs splice

Benchmark created by Mariusz Nowak on


Setup

var arr1 = [], arr2 = [], arr3 = [], val = {}, i = 0, j = 0, k = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
push
++i; arr1.push(val);
ready
splice
arr2.splice(j++, 0, val);
ready
push-or-splice
if (k === arr3.length) {
  ++k;
  arr3.push(val);
} else {
  arr3.splice(k++, 0, val);
}
ready

Revisions

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

  • Revision 1: published by Mariusz Nowak on