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

Fastest function call

Get Adobe Flash player
by jozefchutka 09 Feb 2011
    Embed
/**
 * Copyright jozefchutka ( http://wonderfl.net/user/jozefchutka )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mDUl
 */

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.text.TextField;

    [SWF(width="465", height="465", frameRate="30", backgroundColor="#FFFFFF")]
    public class WonderflApp extends Sprite
    {
        public function WonderflApp():void
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            var tf:TextField = new TextField();
            tf.width = stage.stageWidth;
            tf.height = stage.stageHeight;
            tf.text = "";
            tf.wordWrap = true;
            tf.multiline = true;
            addChild(tf);
            
            var n:int, d:Date, f:Function;
            const C:uint = 10000000;
            var functionFunction:Function = function():int{return 0;}
            const functionConstFunction:Function = function():int{return 0;}
            
            d=new Date,n=C;
            while(--n) functionFunction();
            tf.appendText("functionFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) functionConstFunction();
            tf.appendText("functionConstFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) classFunction();
            tf.appendText("classFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) this.classFunction();
            tf.appendText("this.classFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) private::classFunction();
            tf.appendText("private::classFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) classStaticFunction();
            tf.appendText("classStaticFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) WonderflApp.classStaticFunction();
            tf.appendText("WonderflApp.classStaticFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C,f=classFunction;
            while(--n) f();
            tf.appendText("referenced function: " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            var finalClass:FinalClass = new FinalClass();
            while(--n) finalClass.classFunction();
            tf.appendText("finalClass.classFunction(): " + (new Date().time - d.time) + " ms\n");
            
            d=new Date,n=C;
            while(--n) FinalClass.classStaticFunction();
            tf.appendText("FinalClass.classStaticFunction(): " + (new Date().time - d.time) + " ms\n");
            
         }
         
         private function classFunction():int
         {
             return 0;
         }

        private static function classStaticFunction():int
         {
             return 0;
         }
    }
}

final class FinalClass
{    
    public function classFunction():int
    {
        return 0;
    }
    
    public static function classStaticFunction():int
    {
        return 0;
    }
}