In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Comparing speed of Vector with/out parameters

Comparing speed of a Vector instance created with or without parameters to add elements.

Vectorインスタンスを生成するときの引数設定により、エレメントの加わる速さがどう変わるか試しました。

参考:「Vectorクラス」
http://www.fumiononaka.com/TechNotes/Flash/FN0902001.html
Get Adobe Flash player
by Fumio 11 Feb 2011
    Embed
/**
 * Copyright Fumio ( http://wonderfl.net/user/Fumio )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oUtd
 */

package {
	import flash.display.Sprite;
	import flash.utils.getTimer;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	[SWF(width = "240",height = "180")]
	public class Vector_with_parameters extends Sprite {
		private const MAX_NUMBER:uint = 30000000;
		private var started:int;
		private var my_txt:TextField = new TextField();
		private var label_txt:TextField = new TextField();
		private var my_fmt:TextFormat = new TextFormat();
		public function Vector_with_parameters() {
			// Creating a TextField for display
			createTextField();
			// Starting Test
			testVector();
			testVectorLength();
			testVectorFixed();
		}
		private function testVector():void {
			var myVector:Vector.<int> = new Vector.<int>();
			var nMax:uint = MAX_NUMBER;
			started = getTimer();
			for (var i:uint = 0; i < nMax; i++) {
				myVector[i] = i;
			}
			xTrace((getTimer() - started));
		}
		private function testVectorLength():void {
			var nMax:uint = MAX_NUMBER;
			var myVectorLength:Vector.<int> = new Vector.<int>(nMax,false);
			started = getTimer();
			for (var i:uint = 0; i < nMax; i++) {
				myVectorLength[i] = i;
			}
			xTrace((getTimer() - started));
		}
		private function testVectorFixed():void {
			var nMax:uint = MAX_NUMBER;
			var myVectorFixed:Vector.<int>  = new Vector.<int>(nMax,true);
			started = getTimer();
			for (var i:uint = 0; i < nMax; i++) {
				myVectorFixed[i] = i;
			}
			xTrace((getTimer() - started));
		}
		private function createTextField():void {
			addChild(my_txt);
			addChild(label_txt);
			my_fmt.align = TextFormatAlign.RIGHT;
			// my_txt.x +=  80;
			my_txt.autoSize = TextFieldAutoSize.RIGHT;
			my_txt.defaultTextFormat = my_fmt;
			label_txt.autoSize = TextFieldAutoSize.LEFT;
			label_txt.text = "Vector:\nVector (length):\nVector (fixed):";
		}
		private function xTrace(n:int):void {
			my_txt.appendText((String(n) + "\n"));
		}
	}
}