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

Math.max/minとただのifの速度比較

Get Adobe Flash player
by keno42 12 Jul 2009
/**
 * Copyright keno42 ( http://wonderfl.net/user/keno42 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/58vz
 */

package {
    import flash.display.Sprite;
    import flash.text.*;
    import flash.utils.*;
    public class FlashTest extends Sprite {
        private var tf:TextField = new TextField();
        public function FlashTest() {
            // write as3 code here..
            addChild(tf);
            tf.autoSize = "left";
            var str:String = "";
            var i:int = 0;
            var count:int = 1000000;
            var time:Number = Number(getTimer());
            for( i=0; i < count; i++ ){
                var value:Number = Math.random()*500 - 200;
            }
            str = "random値の生成: " + String(Number(getTimer())-time) + "\n";
            
            time = Number(getTimer());
            for( i=0; i < count; i++ ){
                var value1:Number = Math.random()*500 - 200;
                if( value1 < 0 ) value1 = 0;
                if( value1 > 100 ) value1 = 100;
            }
            str += "random値の生成 + if2つ: " + String(Number(getTimer())-time) + "\n";
            
            time = Number(getTimer());
            for( i=0; i < count; i++ ){
                var value2:Number = Math.random()*500 - 200;
                value2 = Math.min( 100, Math.max( 0, value2 ) );
            }
            str += "random値の生成 + Math.min + Math.max: " + String(Number(getTimer())-time) + "\n";
            
            tf.text = str;
            
        }
    }
}