push vs map and concat (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script src="http://underscorejs.org/underscore-min.js"></script>

Setup

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    var result = [];

Test runner

Ready to run.

Testing in
TestOps/sec
push
for (var i = 0; i < 10; i++) {
  result.push(arr[i]);
}
ready
push.apply
result.push.apply( result, arr );
ready
concat
result = result.concat( arr );
ready
concat map
result = result.concat(_.map(arr, function(i) {
  return i;
}))
ready
append by index
for ( var i = result.length, len = i + arr.length; i < len; ++i ) {
  result[ i ] = arr[ i ];
}
ready
pre-allocated, set by index
result.length += arr.length;
for ( var i = result.length - arr.length, len = result.length; i < len; ++i ) {
  result[ i ] = arr[ i ];
}
ready

Revisions

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