not a tutorial, but a useful resource to people writing heavy applications requiring the fastest execution time:
these will probably apply to AS2 in the most part aswell (in terms of which is faster)
first one:
int,uint,Number, a loop of 100 000 000, simply increment and assignment to another variable
int: 563ms
uint; 2504ms
Number; 1234ms
now, the thing which occured to me here, and i quickly changed in all my applications as of yet, is that uint is for some reason. extremely slow!
as expected int is the fastest for an iteration loop like this, but it should be expected that uint would be the same as int, however for some reason it is very slow, doing more tests, it seems this is also the case, in otherwords, DONT use uint unless you have to
now, another important thing to note when building heavy applications needing as fast an execution as possible, although using an int for an iteration loop is much faster than Number, if you are then using that int in a floating point calculation, it can become alot slower because it has to convert the int to a Number, then back to an int again, so think about this.
next one:
strict data typing VS non strict data typing, and also declaration vs non declaration
again, an iteration loop, this time just int and Number (uint is kind of obsolete now)
(non declared are obviously, not typed either)
int (strict): 562ms
int (non strict): 6385ms
int (not declared): undefined
Number (strict): 1128
Number (non strict): 6385ms
Number (not declared): undefined
as expected, non strict is the same for both, well, because its the same loop, but notice the VAST difference between strict data typing the iteration loop, and non strict data typing
half a second, and one second, compared to 6 and a half seconds!
for the declaration, lets put it this way, it crashed flash player when i didnt declare because it took too long!, so lets try a smaller iteration for non declared comparison, only 2 000 000 this time!
declared Number (strict): 24ms
declared int (strict): 11ms
declared variable (no type still) : 134ms
undeclared variable: 10266ms
i think this is enough to change anyones views on not bothering to declare the variables, look at the difference! 10 seconds, compared to 0.1 second, and when strict data typing to Number, its 0.024seconds, and to int, 0.011second!!!
OK, next, lets see what the difference is in a for loop, for declaring the variable outside for loop, or in the for loop in the following way
var a:int; for(a = 0; a<100000000; ++a) a = a;
for(var a:int = 0; a<100000000; ++a) a = a;
first: 562ms
second: 581ms
so we can see, its very slightly faster to declare the variable outside the for loop, but this brings up the next one, how about ++a in comparison to a++ ?
++a : 553ms
a++ : 573ms
so we see, that ++a is very slightly faster
now, lets have a look at some array loops, first of all:
is it faster to do new Array(); or []; when creating a new array? (using a loop of 2 000 000)
Array(); 3141ms
[]; 1065ms
we can see, that its alot faster to create a new array via [] than new Array();
now lets try push() in comparison to just setting an undefined item in an iteration loop:
(10 000 000 loop)
var b:Array = [];
for(var a:int = 0; a<10000000; ++a) { b.push(a); }
for(var a:int = 0; a<10000000; ++a) { b[a] = a; }
push: 2049ms
[]: 1562ms
we can see here, that using the [] syntax in this style of populating an array is faster than push, but what happens if we define the initial array as new Array(10000000);
[]: 1455ms
if we use new Array() to set the size of the array, before populating it with [], its faster again
now. how about declaring variables outside of a loop, to be used within, rather than inside the loop:
i.e.
var b:int for(var a:int = 0; a<10000000; ++a){ b = a<<1; }
for(var a:int = 0; a<100000000; ++a){ var b:int = a<<1; }
out: 555ms
in: 535ms
so it is slightly faster to declare the variable to be used inside the loop:
anymore speed tests you would like me to run? just ask