So this was an interesting result of this post on Actionscript.org. I ran the suggested test for the speed of iterating over a for-loop, and it wasn’t accurate enough, so I developed the tests below.
Basically, this shows the advantages of different variable types when used in various places in a for-loop. It also shows the relative advantages when used to seek/assign a value to an array. Since computers differ, it is best to just put this in an empty Flash file and run, and see what your results are:
stop();
var t1:Number;
var t2:Number;
var vali:int = 100000000;
var valu:int = 100000000;
var arr:Array = new Array();
var rep:int;
trace("int array init test:" );
for(rep = 0; rep < 5; rep++){
t1 = getTimer();
for(var id:int = 0; id<10000000; id++){ arr[id] = 1;}
t2 = getTimer();
trace(t2 - t1);
}
trace("uint array init test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var ic:uint = 0; ic<10000000; ic++){ arr[ic] = 1;}
t2 = getTimer();
trace(t2 - t1);
}
trace("int array assign test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var ia:int = 0; ia<arr.length; ia++){ arr[ia] = 1;}
t2 = getTimer();
trace(t2 - t1);
}
trace("uint array assign test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var ib:uint = 0; ib<arr.length; ib++){ arr[ib] = 1;}
t2 = getTimer();
trace(t2 - t1);
}
trace("int-int array seek test:" );
for(rep = 0; rep < 4; rep++){
vali = arr.length;
t1 = getTimer();
for(var i7:int = 0; i7<vali; i7++){ arr[i7] = 1; }
t2 = getTimer();
trace(t2 - t1);
}
trace("int-uint array seek test:" );
for(rep = 0; rep < 4; rep++){
valu = arr.length;
t1 = getTimer();
for(var i8:int = 0; i8<valu; i8++){ arr[i8] = 1; }
t2 = getTimer();
trace(t2 - t1);
}
trace("uint-int array seek test:" );
for(rep = 0; rep < 4; rep++){
vali = arr.length;
t1 = getTimer();
for(var i9:uint = 0; i9<vali; i9++){ arr[i9] = 1; }
t2 = getTimer();
trace(t2 - t1);
}
trace("uint-uint array seek test:" );
for(rep = 0; rep < 4; rep++){
valu = arr.length;
t1 = getTimer();
for(var i0:uint = 0; i0<valu; i0++){ arr[i0] = 1; }
t2 = getTimer();
trace(t2 - t1);
}
trace("int-const test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var i1:int = 0; i1<100000000; i1++){}
t2 = getTimer();
trace(t2 - t1);
}
trace("uint-const test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var i2:uint = 0; i2<100000000; i2++){}
t2 = getTimer();
trace(t2 - t1);
}
trace("int-int test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var i3:int = 0; i3<vali; i3++){}
t2 = getTimer();
trace(t2 - t1);
}
trace("int-uint test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var i4:int = 0; i4<valu; i4++){}
t2 = getTimer();
trace(t2 - t1);
}
trace("uint-int test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var i5:uint = 0; i5<vali; i5++){}
t2 = getTimer();
trace(t2 - t1);
}
trace("uint-uint test:" );
for(rep = 0; rep < 4; rep++){
t1 = getTimer();
for(var i6:uint = 0; i6<valu; i6++){}
t2 = getTimer();
trace(t2 - t1);
}