Splice vs Push (v12)

Revision 12 of this benchmark created on


Description

There is no easy way to replace the entire contents of an array in JavaScript. This compares the performance of splice to push.

Preparation HTML

<script>
  var a = [];
  a.length = 10000;
  var b = [];
  b.length = 10000;
  var c = [];
  c.length = 10000;
  var d = [];
  d.length = 10000;
  var aps = Array.prototype.splice;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Splice
a.length = 0;
a.splice(0, 0, 'test');
ready
Push
b.length = 0;
b.push('test');
ready

Revisions

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