msec : dispatchEvent(_event)

by 110100110101101 forked from msec : array[0],dictionary[0] (diff: 65)
addEventListenerについて。
重複した場合は上書き。同じイベントタイプに_onTestEventを100000回追加しても、実行される_onTestEventは1回だけ。
♥0 | Line 63 | Modified 2016-06-13 00:38:33 | 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/Am8i
 */

// forked from 1110101100101001's msec:array[0],dictionary[0] 
package {
    import flash.events.Event;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.utils.Dictionary;
    import flash.utils.getTimer;
    public class FlashTest extends Sprite {
        private var _event:Event;
        private var _dictionary:Dictionary;
        private var _array:Array;
        private var _testCount:int;
        private var _testDispatched:Boolean
        private var _i:int = 0;
        private var _iMax:int = 1000000;
        private var _memo:TextField;
        private var _text:String = "";
        private var _time:Number;
        public function FlashTest() {
            // write as3 code here..
            _event = new Event("test");
            _memo = new TextField();
            var items:Array;
            
            _array = [0];
            _dictionary = new Dictionary();
            
            _dictionary[0] = [];
            
            _time = getTimer();
            for(_i=0; _i<_iMax; ++_i){
                
            }
            _text += String(getTimer() - _time) + " msec : //\n"
            
            _time = getTimer();
            for(_i=0; _i<_iMax; ++_i){
               _array[0]
            }
            _text += String(getTimer() - _time) + " msec : array[0]\n"
            
            _time = getTimer();
            for(_i=0; _i<_iMax; ++_i){
               _dictionary[0]
            }
            _text += String(getTimer() - _time) + " msec : dictionary[0]\n"
            
            _time = getTimer();
            for(_i=0; _i<_iMax; ++_i){
                dispatchEvent(_event);
            }
            _text += String(getTimer() - _time) + " msec : dispatchEvent(_event)\n"
            
            
            _time = getTimer();
            for(_i=0; _i<_iMax; ++_i){
                addEventListener(_event.type, _onTestEvent);
            }
            _text += String(getTimer() - _time) + " msec : addEventListener(_event.type, _onTestEvent);\n"
            
            _time = getTimer();
            for(_i=0; _i<_iMax; ++_i){
                _onTestEvent(_event)
            }
            _text += String(getTimer() - _time) + " msec : _onTestEvent(_event)\n"
            
            _memo.text = _text;
            _memo.width = 465;
            _memo.height = 465;
            addChild(_memo);
        }
        private function _onTestEvent(event:Event):void
        {

        }


    }
}