Recently, I have watched a lot of projects at home.ArticleThey all say that robotlegs's as3-signal is four times more efficient than Adobe's official events. I wrote the following test with suspicion.
It mainly tests when adding events and broadcasting events. First test Code :
// Number of tests var forcount: Int = 9999; // Number of test changes var tmpnum: Int = 0; // The dynamic generation method is used to listen to VaR funobj: Object = {}; for (var I: Int = 0; I <forcount; I ++) funobj ["onff" + I] = function (E: * = NULL ): void {tmpnum ++}; var testsn: Signal = new signal (); var starttime: Int = gettimer (); for (I = 0; I <forcount; I ++) {testsn. add (funobj ["onff" + I]);} trace ("signal Add", I, "listener time", gettimer ()-starttime, "millisecond "); vaR testep: eventdispatcher = new eventdispatcher (); starttime = gettimer (); for (I = 0; I <forcount; I ++) {testep. addeventlistener ("AAA", funobj ["onff" + I]);} trace ("add eventdispatcher", I, "listener time", gettimer ()-starttime, "millisecond"); tmpnum = 0; starttime = gettimer (); testsn. dispatch (); trace ("when signal sends a message", gettimer ()-starttime, "millisecond"); trace ("tmpnum =", tmpnum); tmpnum = 0; starttime = gettimer (); testep. dispatchevent (new event ("AAA"); trace ("When eventdispatcher sends a message", gettimer ()-starttime, "millisecond"); trace ("tmpnum =", tmpnum ); starttime = gettimer (); for (I = 0; I <forcount; I ++) {testsn. remove (funobj ["onff" + I]);} trace ("signal removal", I, "listener time", gettimer ()-starttime, "millisecond "); starttime = gettimer (); for (I = 0; I <forcount; I ++) {testep. removeeventlistener ("AAA", funobj ["onff" + I]);} trace ("eventdispatcher removed", I, "listener time", gettimer ()-starttime, "millisecond ");
The test results are as follows:
1st times
It takes 9999 milliseconds for signal to add 894 listeners
It takes 21 milliseconds for eventdispatcher to add 9999 listeners
Signal message sending time 7 ms
Tmpnum = 9999
Eventdispatcher message sending time 7 ms
Tmpnum = 9999
It takes 9999 milliseconds for signal to remove 150 listeners
Eventdispatcher takes 9999 milliseconds to remove 109 listeners
2nd times
It takes 9999 milliseconds for signal to add 911 listeners
It takes 27 milliseconds for eventdispatcher to add 9999 listeners
The message sending time of signal is 8 milliseconds.
Tmpnum = 9999
Eventdispatcher message sending time 7 ms
Tmpnum = 9999
It takes 9999 milliseconds for signal to remove 146 listeners
Eventdispatcher takes 9999 milliseconds to remove 111 listeners
3rd Times
It takes 9999 milliseconds for signal to add 955 listeners
It takes 28 milliseconds for eventdispatcher to add 9999 listeners
Signal message sending time 7 ms
Tmpnum = 9999
Eventdispatcher message sending time 7 ms
Tmpnum = 9999
It takes 9999 milliseconds for signal to remove 147 listeners
Eventdispatcher takes 9999 milliseconds to remove 110 listeners
The three results are basically the same. The efficiency of eventdispatcher in adding listeners is much faster than signal, while the efficiency of eventdispatcher in sending (hosting messages) and removing messages is almost the same. I really don't think there are other ways to test signal faster than eventdispatcher.
In fact, the code of the listener is not difficult to write. The efficiency is almost the same without traversing and broadcasting messages. I personally suggest using official things. After all, Adobe has made targeted optimizations and has more functions than signal.
I also want to comment on the robotlegs framework. I have too many questions, but I have not finished learning ...... After reading this article, I will try again.