forked from: forked from: -1 が false, それ以上だったら true にするのに、どっちが速いか実験した

by Gleb.Panteleew forked from forked from: -1 が false, それ以上だったら true にするのに、どっちが速いか実験した (diff: 15)
♥0 | Line 28 | Modified 2013-10-24 21:32:09 | MIT License
play

ActionScript3 source code

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

// forked from zahir's forked from: -1 が false, それ以上だったら true にするのに、どっちが速いか実験した
// forked from sugamasao's -1 が false, それ以上だったら true にするのに、どっちが速いか実験した
package {
    import com.actionscriptbible.Example;
    import flash.utils.getTimer;
    
    public class FlashTest extends Example {
        public function FlashTest() {
            // write as3 code here..
            if (false){
                trace("");
            } else if (true){
                trace("ok1")
            } else if (true){
                trace("ok2")
            }
        }
        
        /**
        * 三項演算子で true/false を調べるよ
        */
        private function useTrnaryPperator(str:String):Boolean {
                return str.indexOf("zzzz") > -1 ? true : false
        }
        
        /**
        * ~を使って負数を 0 に(~0 の時は -1 になるので、false扱いにならない)
        */
        private function useComplement(str:String):Boolean{
                return Boolean(~str.indexOf("zzzz"))
        }
        
        private function timerFunction(fn:Function, str:String):int {
                var t:int = getTimer();
                for(var i:uint = 0; i <100000; i++){
                    fn(str);
                }
               return getTimer() - t;
        }
    }
}