forked from: trace を swf 上に。

by mezumona forked from trace を swf 上に。 (diff: 73)
♥0 | Line 78 | Modified 2013-11-26 10:26:07 | MIT License
play

ActionScript3 source code

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

// forked from mezumona's trace を swf 上に。
package {
    import flash.display.Sprite;
    import flash.display.DisplayObjectContainer;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.getTimer;

    public class FlashTest extends Sprite
    {
        private static const LOOP_COUNT:int = 10000000;
        
        public function FlashTest()
        {
            initializeTrace(this);
            startTest();
        }

        private function startTest():void
        {
            var startTime:int;
            for (var i:int = 0; i < 3; i++) {
                startTime = getTimer();
                test1();
                trace(getTimer() - startTime);

                

                startTime = getTimer();
                test2();
                trace(getTimer() - startTime);

                startTime = getTimer();
                test3();
                trace(getTimer() - startTime);

                

                startTime = getTimer();
                test4();
                trace(getTimer() - startTime);
                
                trace("---");
            }
        }

        private function test1():void
        {
            var a:int = 0;
            var n:int = LOOP_COUNT;
            while (n--) {
                dummy(a ||= 1);
            }
        }

        private function test2():void
        {
            var a:int = 0;
            var n:int = LOOP_COUNT;
            while (n--) {
                dummy(a || (a = 1));
            }
        }
        
        private function test3():void
        {
            var n:int = LOOP_COUNT;
            while (n--) {
                var a:int = 0;
                dummy(a ||= 1);
            }
        }

        private function test4():void
        {
            var n:int = LOOP_COUNT;
            while (n--) {
                var a:int = 0;
                dummy(a || (a = 1));
            }
        }

        
        private function dummy(_:int):void { }

        private var tf_:TextField = new TextField();
        public function trace(...rest):void
        {
            tf_.appendText(rest.join(" ") + "\n");
        }

        public function initializeTrace(target:DisplayObjectContainer):void
        {
            tf_.autoSize = TextFieldAutoSize.LEFT;
            target.addChild(tf_);
        }
    }
}