A while back I read a couple of blog posts about the slowness of using uint and int to iterate through for-loops. I needed to do some testing for a little project today and found this is false.
When using the “i” variable in for(var i = 0; i < length; i++) as an input into mathematical operation, especially when doing fractions, Number is faster for obvious reasons. This was established in the posts of the previously mentioned blogs. But when simply iterating over an array which is a very common use-case for for-loops uint is faster. Here is my test setup:
var arr:Array = new Array(1000000);
var length:uint = arr.length;
var startTime:Number = getTimer();
for (var i:uint = 0; i < length; i++)
value = arr[i];
var endTime:Number = getTimer();
trace(”Total Time:”, endTime - startTime);
I was getting around 210 for uints and around 230 for Number. Not a big difference, but I feel dumb for always using Number for this sort of thing without even thinking about how it works.