This sounds like a job for... benchmark!
import flash.utils.getTimer;
function addItems($array:Array, $start:int, $count:int) {
for (var i:Number = $start; i < $start + $count; i++) {
$array.push(i);
}
}
function concatArrays($array1:Array, $array2:Array):Number {
var t1:Number = getTimer();
$array1.concat($array2);
var t2:Number = getTimer();
return t2 - t1;
}
function pushArrays($array1:Array, $array2:Array):Number {
var t1:Number = getTimer();
for each (var item:Object in $array2) {
$array1.push(item);
}
var t2:Number = getTimer();
return t2 - t1;
}
function testBed() {
for (var i:Number = 10000; i <= 100000; i+=10000) {
trace("\n---- New test");
var a1:Array = [];
var a2:Array = [];
addItems(a1, 0, i);
addItems(a2, i, i);
trace("For " + a1.length + " items: ");
trace("concatArrays: " + concatArrays(a1, a2));
trace("pushArrays: " + pushArrays(a1, a2));
}
}
testBed();
As I would have suspected, concat is far faster, especially when dealing with larger arrays.
OUTPUT
---- New test
For 10000 items:
concatArrays: 1
pushArrays: 1
---- New test
For 20000 items:
concatArrays: 1
pushArrays: 4
---- New test
For 30000 items:
concatArrays: 1
pushArrays: 4
---- New test
For 40000 items:
concatArrays: 2
pushArrays: 5
---- New test
For 50000 items:
concatArrays: 1
pushArrays: 6
---- New test
For 60000 items:
concatArrays: 1
pushArrays: 7
---- New test
For 70000 items:
concatArrays: 1
pushArrays: 8
---- New test
For 80000 items:
concatArrays: 2
pushArrays: 12
---- New test
For 90000 items:
concatArrays: 2
pushArrays: 13
---- New test
For 100000 items:
concatArrays: 3
pushArrays: 14
Those numbers are in milliseconds, so as Richard points out, unless your arrays have a huge number of elements, or you are concatenating arrays very frequently, then this is an optimization that is not worth your time