flash on 2012-3-16

by divillysausages
...
@author Damian Connolly
♥0 | Line 90 | Modified 2012-03-16 07:37:53 | MIT License
play

ActionScript3 source code

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

package  
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.clearInterval;
    import flash.utils.Dictionary;
    import flash.utils.getTimer;
    import flash.utils.setInterval;
    /**
     * ...
     * @author Damian Connolly
     */
    public class Test extends Sprite
    {
        private var m_log:TextField = null;
        private var m_interval:int = 0;
        
        public function Test() 
        {
            this.m_log = new TextField;
            this.m_log.width = 300.0;
            this.m_log.height = 300.0;
            this.m_log.border = true;
            this.m_log.wordWrap = true;
            this.m_log.multiline = true;
            this.addChild( this.m_log );
            
            this.m_interval = setInterval( this._test, 2000 );
        }
        
        private function _test():void
        {
            clearInterval( this.m_interval );
            
            var d:Dictionary = new Dictionary;
            var a:Array = new Array;
            var v:Vector.<Blah> = new Vector.<Blah>();
            var iters:int = 1000000;
            var i:int = 0;
            var s:int = 0;
            var b:Blah = null;
            var key:* = null;
            var value:Blah = null;
            
            for ( i = 0; i < iters; i++ )
            {
                b = new Blah;
                d[b] = b;
                a.push( b );
                v.push( b );
            }
            
            // empty test
            this._trace( "Starting tests" );
            s = getTimer();
            for ( i = 0; i < iters; i++ )
                b = null;
            this._trace( "  Empty: " + ( getTimer() - s ) + "ms" );
            
            // for var dictionary
            s = getTimer();
            for ( key in d )
                b = d[key];
            this._trace( "  For var dictionary: " + ( getTimer() - s ) + "ms" );
            
            // for each dictionary
            s = getTimer();
            for each( value in d )
                b = value;
            this._trace( "  For each dictionary: " + ( getTimer() - s ) + "ms" );
            
            // for array
            s = getTimer();
            for ( i = 0; i < iters; i++ )
                b = a[i];
            this._trace( "  For array: " + ( getTimer() - s ) + "ms" );
            
            // for var array
            s = getTimer();
            for ( key in a )
                b = a[key];
            this._trace( "  For var array: " + ( getTimer() - s ) + "ms" );
            
            // for each array
            s = getTimer();
            for each( value in a )
                b = value;
            this._trace( "  For each array: " + ( getTimer() - s ) + "ms" );
            
            // for vector
            s = getTimer();
            for ( i = 0; i < iters; i++ )
                b = v[i];
            this._trace( "  For vector: " + ( getTimer() - s ) + "ms" );
            
            // for var vector
            s = getTimer();
            for ( key in v )
                b = v[key];
            this._trace( "  For var vector: " + ( getTimer() - s ) + "ms" );
            
            // for each vector
            s = getTimer();
            for each( value in v )
                b = value;
            this._trace( "  For each vector: " + ( getTimer() - s ) + "ms" );
        }
        
        private function _trace( msg:String ):void
        {
            trace( msg );
            this.m_log.appendText( msg + "\n" );
        }
        
    }

}

internal class Blah
{
}