msec : array[0xF], array[0x...F]

by 110100110101101
1~5 bit : very fast
6~30 bit : fast
31 bit : slow
32 bit : very slow...
♥0 | Line 267 | Modified 2016-06-13 00:41:18 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            addChild( new Test() );
        }
    }
}






    import flash.display.Sprite;
    class Test extends Sprite {
        public function Test() {
            var note:Note = new Note(this);
            
            var i:int=0;
            var iMax:int=100000;
            
            note.text = ""
            
            var a:int = 0;
            var array:Array = [];
            
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                a = 1;
            }
            note.end( " msec : a = 1; \n" );
            
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0] = 1;
            }
            note.end( " msec : array[0] = 1; \n" );
  
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1] = 1;
            }
            note.end( " msec : array[0x1] = 1; \n" );
 
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x8] = 1;
            }
            note.end( " msec : array[0x8] = 1; \n" );
  
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0xF] = 1;
            }
            note.end( " msec : array[0xF] = 1; \n" );
  
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x10] = 1;
            }
            note.end( " msec : array[0x10] = 1; \n" );

             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1F] = 1;
            }
            note.end( " msec : array[0x1F] = 1; \n" );
 
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x80] = 1;
            }
            note.end( " msec : array[0x80] = 1; \n" );
  
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0xFF] = 1;
            }
            note.end( " msec : array[0xFF] = 1; \n" );
  
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x100] = 1;
            }
            note.end( " msec : array[0x100] = 1; \n" );

             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1FF] = 1;
            }
            note.end( " msec : array[0x1FF] = 1; \n" );
 
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x800] = 1;
            }
            note.end( " msec : array[0x800] = 1; \n" );
  
             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0xFFF] = 1;
            }
            note.end( " msec : array[0xFFF] = 1; \n" );

             //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1000] = 1;
            }
            note.end( " msec : array[0x1000] = 1; \n" );

           
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1FFFF] = 1;
            }
            note.end( " msec : array[0x1FFFF] = 1; \n" );
            
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x80000] = 1;
            }
            note.end( " msec : array[0x80000] = 1; \n" );

                           
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0xFFFFF] = 1;
            }
            note.end( " msec : array[0xFFFFF] = 1; \n" );

                        
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1FFFFF] = 1;
            }
            note.end( " msec : array[0x100000] = 1; \n" );

                        
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1FFFFF] = 1;
            }
            note.end( " msec : array[0x1FFFFF] = 1; \n" );

            
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x800000] = 1;
            }
            note.end( " msec : array[0x800000] = 1; \n" );

            
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0xFFFFFF] = 1;
            }
            note.end( " msec : array[0xFFFFFF] = 1; \n" );



            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1FFFFFFF] = 1;
            }
            note.end( " msec : array[0x10000000] = 1; \n" );
            



            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x1FFFFFFF] = 1;
            }
            note.end( " msec : array[0x1FFFFFFF] = 1; \n" );
            


            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0x80000000] = 1;
            }
            note.end( " msec : array[0x80000000] = 1; \n" );
                        


            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[0xFFFFFFFF] = 1;
            }
            note.end( " msec : array[0xFFFFFFFF] = 1; \n" );
                        

            
            
            
            array  = [];
            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xF] = 1;
            }
            note.end( " msec : array[-0xF] = 1; \n" );
                        


            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFF] = 1;
            }
            note.end( " msec : array[-0xFF] = 1; \n" );
                        


            //--------------------------------------------
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFFF] = 1;
            }
            note.end( " msec : array[-0xFFF] = 1; \n" );
                        


            //-------------------------------------------- 
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFFFF] = 1;
            }
            note.end( " msec : array[-0xFFFF] = 1; \n" );
                        


            //-------------------------------------------- 
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFFFFF] = 1;
            }
            note.end( " msec : array[-0xFFFFF] = 1; \n" );
                        

 
            //-------------------------------------------- 
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFFFFFF] = 1;
            }
            note.end( " msec : array[-0xFFFFFF] = 1; \n" );
                        


            //-------------------------------------------- 
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFFFFFFF] = 1;
            }
            note.end( " msec : array[-0xFFFFFFF] = 1; \n" );
            
            
            
            //-------------------------------------------- 
            note.start();
            for( i=0; i<iMax; ++i ){
                array[-0xFFFFFFFF] = 1;
            }
            note.end( " msec : array[-0xFFFFFFFF] = 1; \n" );
            
             
            
        }
    }








    /////////////////////////////////////////////////////////////////////
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.utils.getTimer;
    /**
    表示だけなら1行で書ける形の着想元
    ! MinimalComps の com.bit101.components.Component 
    https://github.com/minimalcomps/minimalcomps/blob/master/src/com/bit101/components/Component.as
    */
    class Note extends Sprite {
        public function Note( parent:Sprite=null, text:String=" ", x:Number=0,y:Number=0,widthX:Number=200,widthY:Number=100 ){
            
            shape = new Shape();
            bitmap = new Bitmap( new BitmapData( 1,1, true, 0x00000000 ) );
            
            textFormat = new TextFormat()
            textFormat.leftMargin = 0
            textFormat.rightMargin = 0
            textFormat.align = "left"
            textFormat.font = "_等幅"     //EXAMPLE  "_等幅"  "_ゴシック"  "_明朝 "  "_typewriter"  "_serif"  "_sans"
            textFormat.size = 10
            
            textField = new TextField()
            textField.background = false;
            textField.backgroundColor = 0xFFFFFF;
            textField.border = false;
            textField.borderColor = 0x000000;
            textField.textColor = 0x000000;
            textField.autoSize = "left";
            textField.selectable = false;
            textField.text = text;
            textField.defaultTextFormat = textFormat;
            
            this.text = text;
            this.x = x;
            this.y = y;
            textField.width = widthX;
            textField.height = widthY;
            
            displayEnable( parent );
            
            addEventListener( Event.ENTER_FRAME, onEnterFrame );
            
        }
        
        private function onEnterFrame( event:Event ):void {
            textField.text = text;
        }
        
        public function displayEnable( parent:Sprite ):void{
            if( parent ){
                parent.addChild( this );
                addChild( textField );
                addChild( shape );
                addChild( bitmap );
            }
        }
        
        public function displayDisenable():void{
            if( parent ){
                parent.removeChild( this );
                removeChild( textField );
                removeChild( shape );
                removeChild( bitmap );
            }
        }
        
        public function start( startText:String = "" ):void{
            startTime = getTimer();
            text = text + startText;
        }
        public function end( endText:String = "" ):void{
            endTime = getTimer();
            elapsedTime = endTime - startTime;
            text = text + elapsedTime.toString() + endText;
        }
        
        public function toBitmapData():BitmapData{
            var result:BitmapData
            result = new BitmapData( this.width, this.height, true, 0x00000000 );
            result.draw( this );
            return result;
        }
        
        public var elapsedTime:Number = 0;
        public var endText:String = "";
        public var endTime:Number = 0;
        public var iMax:uint = 1000000;
        public var startText:String = "";
        public var startTime:Number = 0;
        
        
        public var text:String
        public var textFormat:TextFormat
        public var textField:TextField
        public var bitmap:Bitmap;
        public var shape:Shape
    }