Splice vs Push (v7)

Revision 7 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 = [5,6,7,8];
  var b1 = [0, 0, 1,2,3,4];
  var b2 = [1,2,3,4];
  var aps = Array.prototype.splice;
  var ap = Array.prototype.push;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Splice
aps.apply(a, b1);
ready
Push
ap.apply(a, b2);
 
ready

Revisions

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