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

Stack Overflow: How to measure how long the function works

Get Adobe Flash player
by Mattias 01 Oct 2011
    Embed
/**
 * Copyright Mattias ( http://wonderfl.net/user/Mattias )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/d5WS
 */

package
{
    import flash.display.Sprite;
    import flash.utils.getTimer;
    import flash.text.TextField;

    public class FlashTest extends Sprite
    {
        
        private var _debugText : TextField;
        
        public function FlashTest()
        {
            var timeStarted : int = getTimer();
            var timeCompleted : int;

            runReallyWackyFunction();

            timeCompleted = getTimer();

            setupDebugText("total time: " + (timeCompleted - timeStarted) + "ms");
        }

        private function setupDebugText(message : String) : void
        {
            _debugText = new TextField();
            _debugText.x = 20;
            _debugText.y = 20;
            _debugText.textColor = 0xFFCC00;
            _debugText.backgroundColor = 0x000000;
            _debugText.background = true;
            _debugText.autoSize = "left";
            _debugText.text = message;
            addChild(_debugText);
        }
        
        private function runReallyWackyFunction() : void
        {
            // put wacky stuff here
            var testUpdates : int = 30000;
            
            while(testUpdates--)
            {
                with(graphics)
                {
                    beginFill(Math.random()*0x000000, 0.25);
                    drawCircle(Math.random() * stage.width, Math.random() * stage.height, 10);
                    endFill();
                }

            }

        }
    }

}