Trace Test

by rfkrocktk
♥0 | Line 41 | Modified 2010-03-26 08:05:45 | MIT License
play

ActionScript3 source code

/**
 * Copyright rfkrocktk ( http://wonderfl.net/user/rfkrocktk )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7kgS
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    public class FlashTest extends Sprite {
        
        private var textfield:TextField;
        
        public function FlashTest() {
        		this.textfield = new TextField();
        		this.textfield.width = 1024;
        		this.textfield.height = 768
        		this.textfield.defaultTextFormat = new TextFormat("_sans");
        		this.addChild(textfield);
        		
			runTest(100);
			runTest(1000);
			runTest(10000);
			runTest(50000);
        }
        
        private function runTest(loopcount:Number):void {
        		var logger:Object = {};
        		logger.debug = truelog;
        		
        		var startTime:Number = new Date().time;
        		
        		for (var i:uint = 0; i < loopcount; i++) {
        			logger.debug("TRACE A HUGE TEXT MESSAGE TO THE OUTPUT PANEL AND LOTS OF OTHER THINGS AS WELL!");
        		}
        		
        		var endTime:Number = new Date().time;
        		
        		textfield.appendText(loopcount + " iterations with trace: " + (endTime-startTime) + " milliseconds.\n");
        		
        		logger.debug = fakelog;
        		
        		startTime = new Date().time;
        		
        		for (i = 0; i < loopcount; i++) {
        			logger.debug("TRACE A HUGE TEXT MESSAGE TO THE OUTPUT PANEL AND LOTS OF OTHER THINGS AS WELL!");
        		}
        		
        		endTime = new Date().time;
        		
        		textfield.appendText(loopcount + " iterations without trace: " + (endTime-startTime) + " milliseconds.\n");
        }
        
        private function truelog(...args):void {
        		trace.apply(this, args);
        }
        
        private function fakelog(...args):void {
        		
        }
    }
}