flash on 2011-5-24

by divillysausages
...
@author Damian Connolly
♥0 | Line 54 | Modified 2011-05-24 17:07:12 | 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/fB6U
 */

package  
{
    import flash.display.Sprite;
    import flash.sampler.getSize;
    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_obj:Object         = new Object;
        private var m_dict:Dictionary    = new Dictionary;
        private var m_total:int            = 10000;
        private var m_interval:int        = 0;
        private var m_text:TextField    = new TextField;
        
        public function Test() 
        {
            for ( var i:int = 0; i < this.m_total; i++ )
            {
                this.m_obj["something" + i] = i;
                this.m_dict["something" + i] = i;
            }
            
            this.m_interval = setInterval( this._test, 2000 );
            
            this.m_text.width = 400;
            this.m_text.height = 200;
            this.addChild( this.m_text );
        }
        
        private function _test():void
        {
            clearInterval( this.m_interval );
            var i:int = 0;
            var s:int = 0;
            var t:int = 1000000;
            var r:int = 0;
            var index:int = this.m_total - 1;
            
            this._log( "Testing object" );
            s = getTimer();
            for ( i = 0; i < t; i++ )
                r = this.m_obj[index];
                
            this._log( "  Object took " + ( getTimer() - s ) + "ms, with a size of " + getSize( this.m_obj ) );
            
            this._log( "Testing dictionary" );
            s = getTimer();
            for ( i = 0; i < t; i++ )
                r = this.m_dict[index];
                
            this._log( "  Dictionary took " + ( getTimer() - s ) + "ms, with a size of " + getSize( this.m_dict ) ) ;
        }
        
        private function _log( msg:String ):void
        {
            trace( msg );
            this.m_text.appendText( msg + "\n" );
        }
        
    }

}