Forked from: clockmaker's [最適化 Tips] SpriteとMovieClipってそんなに変わるの? diff:68 Cast系も追加してみる CastSpriteとかでもやろうと思ってコピペ katapad forked:1favorite:0lines:155license : MIT License modified : 2009-09-28 03:42:05 Embed Tweet // forked from clockmaker's [最適化 Tips] SpriteとMovieClipってそんなに変わるの? // forked from muta244's [最適化 Tips] 変数名の長さによる処理速度の違い // CastSpriteとかでもやろうと思ってコピペ package { import flash.display.*; import flash.events.*; import flash.text.*; import flash.utils.*; import flash.system.*; import jp.progression.casts.*; public class Main extends Sprite { static private const _NUM_TIMES:uint = 2000; private var wrap:Sprite; private function _init():void { while(wrap.numChildren) wrap.removeChildAt(0); _debug( "各テスト " + _NUM_TIMES + " 回処理させた計算結果 [単位 : ミリ秒]\n" + "(誤差は多少生じます)\n" ); var old:int = System.totalMemory; _measure("Sprite", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var sp:Sprite = new Sprite(); wrap.addChild(sp) } }); _debug("(Spriteのメモリ使用量 : " + int((System.totalMemory - old)/1000) + "KB"); while(wrap.numChildren) wrap.removeChildAt(0); System.gc(); _debug("") var old1:int = System.totalMemory; _measure("MovieClip", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var mc:MovieClip = new MovieClip(); wrap.addChild(mc) } }); _debug("(MovieClipのメモリ使用量 : " + int((System.totalMemory - old1)/1000) + "KB"); while(wrap.numChildren) wrap.removeChildAt(0); System.gc(); _debug("") var old2:int = System.totalMemory; _measure("CastSprite", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var mc:CastSprite = new CastSprite(); wrap.addChild(mc) } }); _debug("(CastSpriteのメモリ使用量 : " + int((System.totalMemory - old2)/1000) + "KB"); while(wrap.numChildren) wrap.removeChildAt(0); System.gc(); _debug("") var old3:int = System.totalMemory; _measure("CastMovieClip", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var mc:CastMovieClip = new CastMovieClip(); wrap.addChild(mc) } }); _debug("(CastMovieClipのメモリ使用量 : " + int((System.totalMemory - old3)/1000) + "KB"); while(wrap.numChildren) wrap.removeChildAt(0); System.gc(); _debug("") var old4:int = System.totalMemory; _measure("CastButton", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var mc:CastButton = new CastButton(); wrap.addChild(mc) } }); _debug("(CastButtonのメモリ使用量 : " + int((System.totalMemory - old4)/1000) + "KB"); while(wrap.numChildren) wrap.removeChildAt(0); System.gc(); _debug("") var old5:int = System.totalMemory; _measure("MovieClip", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var mc:MovieClip = new MovieClip(); wrap.addChild(mc) } }); _debug("(MovieClipのメモリ使用量 : " + int((System.totalMemory - old5)/1000) + "KB"); while(wrap.numChildren) wrap.removeChildAt(0); System.gc(); _debug("") var old6:int = System.totalMemory; _measure("Sprite", function ():void { for (var i:uint = 0; i < _NUM_TIMES; i++) { var sp:Sprite = new Sprite(); wrap.addChild(sp) } }); _debug("(Spriteのメモリ使用量 : " + int((System.totalMemory - old6)/1000) + "KB"); _debug("\n結果については言及しませんので, 各自ご判断ください."); } private var _field:TextField; private var _time:uint; public function Main():void { _setup(); _init(); } private function _measure(title:String, func:Function, ...params):void { _time = getTimer(); func.apply(null, params); _time = getTimer() - _time; _debug("[ " + title + " ] --> " + _time + " ms"); } private function _debug(log:String):void { _field.appendText(log + "\n"); } private function _setup():void { wrap = new Sprite addChild(wrap) _field = new TextField(); _field.width = stage.stageWidth - 40; _field.height = stage.stageHeight - 60; _field.x = 20; _field.y = 60; var format:TextFormat = _field.defaultTextFormat; format.font = "_sans"; _field.defaultTextFormat = format; addChild(_field); var button:Sprite = new Sprite(); button.graphics.lineStyle(1, 0xBBBBBB); button.graphics.beginFill(0xEEEEEE); button.graphics.drawRoundRect(0, 0, 100, 20, 5, 5); button.graphics.endFill(); addChild(button); button.x = 20; button.y = 20; button.mouseChildren = false; button.buttonMode = true; var field:TextField = new TextField(); field.width = 100; field.height = 20; field.htmlText = "<p align='center'><font face='_sans'>再計算</span></p>"; button.addChild(field); button.addEventListener(MouseEvent.CLICK, function ():void { _field.text = ""; _init(); }); } } } Code Fullscreen Preview Fullscreen System.totalMemory System.gc removeChildAt numChildren CastMovieClip CastSprite CastButton title MovieClip Math.log getTimer mouseChildren defaultTextFormat drawRoundRect apply buttonMode htmlText TextField appendText MouseEvent.CLICK sort new page view favorite forked pv290 Cast系も追加してみる prog ver 4 katapad forked:0 favorite:1lines:155 (diff:4)