forked from: Vector class versus Array class
要素がリファレンスタイプの場合ほとんど速度変わらない。
/**
* Copyright coppieee ( http://wonderfl.net/user/coppieee )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6BR0
*/
//要素がリファレンスタイプの場合ほとんど速度変わらない。
package {
import flash.display.Sprite;
import flash.utils.getTimer;
import flash.text.TextField;
public class Vector_vs_Array extends Sprite {
private static var my_txt:TextField = new TextField();
private const MAX_NUMBER:int = 500000;
public function Vector_vs_Array() {
addChild(my_txt);
testArray();
testVector();
testVectorFixed();
}
private function testArray():void {
var started:int = getTimer();
var xs:Array = [];
for (var i:int = 0; i < MAX_NUMBER; i++) {
xs[i] = new Foo();
}
xTrace(getTimer() - started);
}
private function testVector():void {
var started:int = getTimer();
var xs:Vector.<Foo> = new Vector.<Foo>();
for (var i:int = 0; i < MAX_NUMBER; i++) {
xs[i] = new Foo();
}
xTrace(getTimer() - started);
}
private function testVectorFixed():void {
var xs:Vector.<Foo> = new Vector.<Foo>(MAX_NUMBER,true);
var started:int = getTimer();
for (var i:int = 0; i < MAX_NUMBER; i++) {
xs[i] = new Foo();
}
xTrace(getTimer() - started);
}
private static function xTrace(n:int):void {
my_txt.appendText(n + "\n");
}
}
}
class Foo{}