亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

編寫高效率的AS3代碼的小技巧

 更新時間:2009年02月27日 20:50:45   作者:  
最近我研究了一些AS3代碼優(yōu)化的文章,一般都是集中在研究loops 和 Number types上的,本文不在重復(fù)類似的測試
下面是我的一些測試結(jié)果

Array & Object constructing

構(gòu)造數(shù)組和對象的時候,new Array() and new Object()要比 [] and {}慢3倍的時間

Index Number type for Arrays

數(shù)組的數(shù)字索引類型

ist[int(0)] 比list[0]要快

Create Array vs. Updating Array

再循環(huán)語句中避免多次創(chuàng)建數(shù)組,最好創(chuàng)建一次用多次更新內(nèi)容替換
Nulling Array vs. Splicing Array

對于龐大的數(shù)組而言就行splice操作是比較耗成本的,要盡量避免

When working with large Arrays splicing is obviously an expensive operation, you can avoid this by nulling the index and skipping it in a null scenario. If you need to splice in order to keep the Array length low. Then store these nulled indexes in another trash Array once the garbage count has reached a limit you've defined loop through the numerically sorted trash indexes deleting splices in bulk. This concept is demonstrated in Tweensy.

 

Nulling Object vs. Delete Object

delete一個對象的屬性要比把該屬性設(shè)置為null 更昂貴,所以對于對象的屬性最好設(shè)置為null

Nesting Loops(嵌套循環(huán))

多次嵌套循環(huán)效率差,所以最好保證循環(huán)在2層以內(nèi)

 

Inline code vs. function references

如果在時間幀上的函數(shù)很長而且執(zhí)行時間長,最好,把該函數(shù)分成多個小的函數(shù)執(zhí)行。

 

這樣可以縮短執(zhí)行時間提高效率

Arguments vs. variable referencing

盡量最小化函數(shù)的參數(shù)個數(shù)

 

 

Function apply scoping do it or not?

Scoping function.apply is a little bit slower than not so if you don't have to then don't.

 

 

Array push vs. Array index

用設(shè)置index的方式來代替使用數(shù)組函數(shù)push

比如

list[list.length] = data; 要比直接用push快600%;

 

Array emptying - length 0 vs. A new Array

如果你需要設(shè)置一個空數(shù)組,有一個方便的辦法去選擇,就是通過設(shè)置它的length屬性為0

或者你會認(rèn)為這么做是不錯的選擇,原因是它能節(jié)省內(nèi)存,但是事實(shí)上這樣做的執(zhí)行速度不如直接new array的效率高

當(dāng)然,如果你需要在一次循環(huán)中清除多于510個數(shù)組為空時,用length設(shè)置為0的時候會更好

 

Var declarations on multiple lines vs. Var declarations on a single line

 

將變量聲明在一行中,要比聲明多行更好,效率更高

i.e.
var a:int=0, b:int=0, c:int=0;
vs.
var a:int=0;
var b:int=0;
var c:int=0;

 

Using Xor to swap variables

如果你想去交換變量,但是又不想創(chuàng)建新的變量的時候,可以用xor

如:

 a = a^b;
b = a^b;
a = a^b;

 

Multiplication vs. Division

乘法的運(yùn)算速率總是比出發(fā)快,比如5000/1000 要比 5000*0.001快130%;

 

 

Type casting comparison 強(qiáng)制轉(zhuǎn)換類型對比

When type casting the keyword as is 250% more efficient than casting by Type(item); Though surprisingly not using either is about 1400% more efficient.

 

建議使用對應(yīng)的類型的變量進(jìn)行比較

同類型的比較效率高的多

 

 

Long vs Short variable names

盡量用短的變量名

相關(guān)文章

最新評論