ActionScript 3 Optimizing Performance Vector and for each vs arrays and for


Example

Using the Vector.<T> type and the for each loop is more performant than a conventional array and for loop:

Good:

var list:Vector.<Sprite> = new <Sprite>[];

for each(var sprite:Sprite in list) {
    sprite.x += 1;
}

Bad:

var list:Array = [];

for (var i:int = 0; i < list.length; i++) {
    var sprite:Sprite = list[i];

    sprite.x += 1;
}