msec : true false ... if ?:; switch

by 110100110101101
slow ... switch > ?:; > if ... fast
♥0 | Line 46 | Modified 2016-06-13 00:39:38 | MIT License
play

ActionScript3 source code

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

package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.utils.getTimer;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            var i:int,iMax:int = 10000000;
            var memo:TextField = new TextField();
            var text:String = iMax.toString() + " loops \n";
            var msec:Number = 0;
            
            var testBoolean:Boolean = true;
            
            ///////////////////////////////////
            msec = getTimer();
            for(i=0; i<=iMax; ++i)
            {
                if(testBoolean)
                {
                    
                }
                else
                {
                    
                }
            }
            text += "\n" + String(getTimer()-msec) + " msec : "
            + "if"
            
            //////////////////////////////////
            msec = getTimer();
            for(i=0; i<=iMax; ++i)
            {
                testBoolean ? true : false;
            }
            text += "\n" + String(getTimer()-msec) + " msec : "
            + "? : ;"
            
            ///////////////////////////////////
            msec = getTimer();
            for(i=0; i<=iMax; ++i)
            {
                switch(testBoolean)
                {
                    case true:break;
                    case false:break;
                }
            }
            text += "\n" + String(getTimer()-msec) + " msec : "
            + "switch"
            
            memo.text = text;
            addChild(memo);
        }
    }
}