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

loop test

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

// forked from cpu_t's abs test
package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.utils.getTimer;
    public class FlashTest extends Sprite {
        
        private const LOOP_NUM:Number = 10000000;
        
        public function FlashTest() {
            // write as3 code here..
            var tf:TextField = new TextField();
            addChild(tf);
            tf.width = stage.stageWidth;
            tf.height = stage.stageHeight;
            
            var i:int; var start:Number;
            
            var array:Array = new Array(LOOP_NUM);
            
            trace("for(i = 0; i < array.length; i++)");
            start = getTimer();
            for(i = 0; i < array.length; i++)
            {
            }
            trace(getTimer() - start, "ms");
            trace("");
            
            trace("for(i= array.length - 1; i >= 0; i--)");
            start = getTimer();
            for(i= array.length - 1; i >= 0; i--)
            {
            }
            trace(getTimer() - start, "ms");
            trace("");
            
            trace("while(i--)");
            start = getTimer();
            i = array.length - 1;
            while(i--)
            {
            }
            trace(getTimer() - start, "ms");
            trace("");
            
            function trace(...rest):void {
                tf.appendText(rest.join(" ") + "\n");
            }
            
        }
    }
}