In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

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

Get Adobe Flash player
by zahir 25 Apr 2010
    Embed
/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uOuv
 */

// 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..
            trace("cast testing(useTrnaryPperator)-----------");
            trace("cast 三項演算子1.=>",useTrnaryPperator("aaaa"));
            trace("cast 三項演算子2.=>",useTrnaryPperator("zzzz"));
            trace("cast testing(useComplement)-----------");
            trace("cast 補数1.=>",useComplement("aaaa"));
            trace("cast 補数2.=>",useComplement("zzzz"));

            trace("timer test");
            trace("timerFunction[三項演算子] all false", timerFunction(useTrnaryPperator, "aaaa"));
            trace("timerFunction[三項演算子] all true", timerFunction(useTrnaryPperator, "zzzz"));
            
            trace("timerFunction[補数] all false", timerFunction(useComplement, "aaaa"));
            trace("timerFunction[補数] all true", timerFunction(useComplement, "zzzz"));
            
        }
        
        /**
        * 三項演算子で 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;
        }
    }
}