Decrement versus Increment in Loop without Constant
/**
* Copyright Fumio ( http://wonderfl.net/user/Fumio )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/li9w
*/
// forked from Fumio's Decrement versus Increment in Loop
package {
import flash.display.Sprite;
import flash.utils.getTimer;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class Decrement_vs_Increment extends Sprite {
private static var my_txt:TextField = new TextField();
private const MAX_NUMBER:int = 500000000;
private var i:int;
private var started:int;
public function Decrement_vs_Increment() {
addChild(my_txt);
my_txt.autoSize = TextFieldAutoSize.LEFT;
testDecrement();
testIncrement();
testDecrementPost();
}
private function testDecrement():void {
i = MAX_NUMBER;
started = getTimer();
while (--i > -1) {
}
xTrace(getTimer() - started);
}
private function testIncrement():void {
started = getTimer();
while (++i < 500000000) {
}
xTrace(getTimer() - started);
}
private function testDecrementPost():void {
i = MAX_NUMBER;
started = getTimer();
while (i-- > 0) {
}
xTrace(getTimer() - started);
}
private static function xTrace(n:int):void {
var trace_str:String = String(n);
my_txt.appendText(trace_str + "\n");
// trace(trace_str);
}
}
}