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

関数のオーバーヘッドありすぎない?

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/paHC
 */

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:Number = 0;
            var j:Number;
            var count:int = 2000000;
            var time:Number;
            
            var func1:Function = function(value:Number):Number{
                return (value + value * value) / value;
            }
            
            time = Number(getTimer());
            for( i=0; i < count; i++ ){
                j = (i + i * i) / i;
            }
            str = "インライン: " + String(Number(getTimer())-time) + "\n";
            
            time = Number(getTimer());
            for( i=0; i < count; i++ ){
                j = func(i);
            }
            str += "private関数: " + String(Number(getTimer())-time) + "\n";
            
            time = Number(getTimer());
            for( i=0; i < count; i++ ){
                j = func1(i);
            }
            str += "関数: " + String(Number(getTimer())-time) + "\n";
            
            tf.text = str;
            
        }
        private function func(value:Number):Number{
            return (value + value * value) / value;
        }    
    }
}