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

graphicsを書くとき

ちょっと気になった事
 いつもwithで書いてるけど
実際何が一番早いんだろう
Get Adobe Flash player
by 178ep3 30 Nov 2009

    Talk

    KRFX_ERRORISM at 01 Dec 2009 03:22
    wow thats a huge difference, but what time does it take to create the shape instance?

    Tags

    Embed
/**
 * Copyright 178ep3 ( http://wonderfl.net/user/178ep3 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/3hwp
 */

//	ちょっと気になった事
// いつもwithで書いてるけど
//	実際何が一番早いんだろう
package
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.getTimer;

	public class ExTime extends Sprite
	{
		public function ExTime()
		{
			var text:TextField = addChild(new TextField())as TextField;
			text.autoSize = TextFieldAutoSize.LEFT;
			var i:int=0;
			
			text.appendText("毎回newすると\n");
			var t:int = getTimer();
			for(i=0; i<100000; i++)
			{
				var n:Shape = new Shape();
				n.graphics.beginFill(0);
				n.graphics.drawCircle(0,0,1);
				n.graphics.endFill();
			}
			
			text.appendText("normal : " + String(getTimer()-t) + "ms\n");
			
			t = getTimer();
			for(i=0; i<100000; i++)
			{
				var n2:Shape = new Shape();
				var g:Graphics = n2.graphics;
				g.beginFill(0);
				g.drawCircle(0,0,1);
				g.endFill();
			}
			text.appendText("graphics : " + String(getTimer()-t) + "ms\n");
			
			t = getTimer();
			for(i=0; i<100000; i++)
			{
				var n3:Shape = new Shape();
				with(n3.graphics)
				{
					beginFill(0);
					drawCircle(0,0,1);
					endFill();
				}
			}
			text.appendText("with : " + String(getTimer()-t) + "ms\n");
			
			text.appendText("\n 同じshapeで \n");

			
			t = getTimer();
			var a:Shape = new Shape();
			for(i=0; i<100000; i++)
			{
				a.graphics.clear();
				a.graphics.beginFill(0);
				a.graphics.drawCircle(0,0,1);
				a.graphics.endFill();
			}
			
			text.appendText("normal : " + String(getTimer()-t) + "ms\n");
			
			t = getTimer();
			a = new Shape();
			var gg:Graphics = a.graphics;
			for(i=0; i<100000; i++)
			{
				gg.clear();
				gg.beginFill(0);
				gg.drawCircle(0,0,1);
				gg.endFill();
			}
			text.appendText("graphics : " + String(getTimer()-t) + "ms\n");
			
			t = getTimer();
			a = new Shape();
			for(i=0; i<100000; i++)
			{
				with(a.graphics)
				{
					clear();
					beginFill(0);
					drawCircle(0,0,1);
					endFill();
				}
			}
			text.appendText("with : " + String(getTimer()-t) + "ms");
		}
	}
}