Array.prototype.push.apply vs concat (v44)

Revision 44 of this benchmark created on


Description

This page tests speed of two different methods for array concatenation. Array method concat() has no side effects (it creates a new array to store its result in), while Array.prototype.push.apply(A, [1, 2, ...]) extends the array A.

Preparation HTML

<script>
  var a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
      b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
  var arrPush = Array.prototype.push;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
concat
a = a.concat(b);
ready
Array#push.apply
Array.prototype.push.apply(a, b);
ready
Array#push with loop
var i = 0,
  c = b.length;

for (; i < c; ++i) {
  a.push(b[i]);
}
ready
Cached Array#push
arrPush.apply(a, b);
ready

Revisions

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