速度比較用テンプレ

by zahir
タダのテンプレ
♥2 | Line 60 | Modified 2010-11-01 23:41:52 | MIT License
play

ActionScript3 source code

/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rMVQ
 */

/*
    あくまでも参考値。
    PCでは効果がなく感じてもスマートフォンとかではあるかも
*/
package {
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.utils.getTimer;
    
    public class FlashTest extends Sprite {
        private const LOOP:int = 1000000;
        private var t:TextField;
        
        public function FlashTest() {
            addChild( ( t= new TextField() ) ).width = t.height = 465;
            addEventListener( MouseEvent.CLICK, onClick );
            ex();
        }
        
        private function onClick( e:MouseEvent ):void
        {
            ex();
        }

        private function ex():void
        {
            var i:int = 0;                                      
            var time1:int;
            var time2:int;
            var recode:Array = [];
            var count:int = 0;
            t.text = "各 " + LOOP + " 回ループ\n\n";
            
            // ここから処理
            // ここまで処理
            
            /* templete
            time1 = getTimer();
            for( i = 0; i<LOOP; i++ )
            {
                
            }
            time2 = getTimer() - time1;
            recode[count++] = new TimeData( "", time2, "" );
            */
            
            if( recode.length )
            {
                listup( recode );
            }
            
            t.appendText("clickで再計算");
        }
        private function listup( recode:Array ):void
        {
            var str:String = "";
            recode.sortOn( "time", Array.NUMERIC );
            var max:int = (recode[ recode.length - 1 ] as TimeData).time;
            for( var i:int = 0, len:int = recode.length; i<len; i++)
            {
                var data:TimeData = recode[i] as TimeData;
                var n:int = max / data.time * 100;
                str += data.title + " :: " + data.time + " ms\n\t\t最低速に比べて約 " + n + " %高速 \n";
                if(data.ms == "") str += "\n";
                else str += "\t\t" + data.ms  + "\n\n";
            }
            t.appendText( str );
        }
    }
}
class TimeData
{
    public var title:String;
    public var time:int;
    public var ms:String; // なんか、おまけ要素
    public function TimeData( title:String = "", time:int = 0 , ms:String = "")
    {
        this.title = title;
        this.time = time;
        this.ms = ms;
    }
}

Forked