Saturday, March 10, 2012

Break is slightly faster in a do loop.

//When I say slightly faster, I mean the difference in this
//code is about 20 milliseconds... You should probably just
//use whatever is easiest for.


var xx:int = 0;
var loopTrue:Boolean;
var tt:int;
var t1:int;
var t2:int;
var maxVal:int = 7654321;

t1 = getTimer();
xx=0;
do{
 xx++;
 if(xx>maxVal){break;}
}while(true);
t2 = getTimer();
tt = t2-t1;
trace("method1===" + tt);


t1 = getTimer();
xx=0;
loopTrue=true;
do{
 xx++;
 if(xx>maxVal){loopTrue=false;}
}while(loopTrue);
t2 = getTimer();
tt = t2-t1;
trace("method2===" + tt);

No comments:

Post a Comment