Method for improving flash program efficiency

xiaoxiao2021-03-06  34

With the constant power of Flash's ActionScript function, it is more and more, but the most headache of many AS programmers is that Flash's program is too low. Even if FlashPlayer7 is more efficient than FlashPlayer6, 2 ~ 8 times, but still low, especially in handheld equipment (all components of Flash2004 on the PPC can not be used, need to be developed), so many AS programmers continue to study comparison Which method in action is higher, which directive is faster. Even some people use the While loop without speaking (because many tests indicate that the While loop is faster than the for loop), but this practice is actually not fast. Let the program read / write more trouble, in fact, it is really improving the efficiency of the program, which is more fast similar to the While for loop, but to find the efficiency of the bottleneck of the program efficiency, the most critical to see algorithm, even The fastest computer language (such as c), if the algorithm is not good, most execution time is wasted, not fully utilized, the program will be very slow, and if the algorithm is properly, it may solve the problem. Don't have a lot of calculations, so even if the efficiency is very efficient Action, it can be solved soon (although the action is slow, it can cycle hundreds of thousands of times per second, and can do a lot of things in a short time, The so-called slow is a faster program language) here, let's not talk about algorithms, separate from FlashPlayer, how can we improve the efficiency of Action? To improve efficiency, you must grasp the fundamental, and seize why Flash is slow. The Action execution is low, and the most fundamental reason is that the action is an explanatory language. Each code requires FlashPlayer to explain the execution, this is the root cause of the Action execution efficiency, then improve the efficiency of the Action? Which sentence Is Action more efficient, all Action is PLAYER to resolve, and it is certain that it is not a big difference. Of course, try to use Action to handle everyone knowing that flashplayer is written in C language, the Flash inside All built-in functions are definitely implemented using C language (although flash executes Action is slow, the built-in function of Flash is indeed very fast, such as the method under Flash under Math is very efficient), then if we You can use the method of treating us with action to deal with the Flash internal method. If you have to use the built-in method instead of Action, this depends on the personal level and the degree of familiarity of action, hereby an example Let's explain: Action programmer I know that the efficiency of the Action processing string is very low, but the low can, the following code can be explained: var str = "abcde"; var TMP = ""; var time1 = getTimer (); for (var i = 0; i <10000; i ) {TMP = Str;} Trace (getTimer () - TIME1); // 1665 Connect 10,000 5 letters of strings to 1.5S or more (CPU: PM1.4) If you change to 10 letters, you need to use about 4s, 15 letters, about 5.5s, the time of the string, the speed of the string is getting lower and lower, how can the string faster ? Take a look at the code below: Time1 = getTimer (); var TMPA = new array (); for (var i = 0; i <1000; i ) {TMPA [i] = Str;} var TMP1 = TMPA .join (""); trace (GetTimer () - TIME1; Trace (TMP1 == TMP);

转载请注明原文地址:https://www.9cbs.com/read-64466.html

New Post(0)