Splice vs Push (v4)

Revision 4 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.

Setup

var a = Array(1e4 + 1).join('a').split(),
       b = Array(1e4 + 1).join('b').split();

Test runner

Ready to run.

Testing in
TestOps/sec
Splice 1
a.splice.apply(a, [0, a.length].concat(b));
ready
Splice 2
a.length = 0;
a.splice.apply(a, [0, 0].concat(b));
ready
Push
a.length = 0;
a.push.apply(a, b);
ready
Concat
a = a.concat(b);
ready

Revisions

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