Comparing local variable with property
♥0 |
Line 57 |
Modified 2010-12-31 18:01:34 |
MIT License
archived:2017-03-09 21:01:58
ActionScript3 source code
/**
* Copyright Fumio ( http://wonderfl.net/user/Fumio )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/aoRG
*/
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.utils.getTimer;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
[SWF(width = "240",height = "180")]
public class ComparingLocalWithProperty extends Sprite {
private const AMOUNT:uint = 5000000;
private var started:uint;
private var my_txt:TextField = new TextField();
private var label_txt:TextField = new TextField();
private var my_fmt:TextFormat = new TextFormat();
public function ComparingLocalWithProperty() {
// Creating a TextField for display
createTextField();
// Starting test
useLocal();
useProperty();
}
private function useLocal():void {
var mySprite:Sprite = new Sprite();
started = getTimer();
for (var i:uint = 0; i < AMOUNT; i++) {
var nX:Number = mySprite.x + 1;
if (nX > 500) {
nX -= 500;
}
mySprite.x = nX;
}
xTrace(getTimer() - started);
}
private function useProperty():void {
var mySprite:Sprite = new Sprite();
started = getTimer();
for (var i:uint = 0; i < AMOUNT; i++) {
mySprite.x += 1;
if (mySprite.x > 500) {
mySprite.x -= 500;
}
}
xTrace(getTimer() - started);
}
private function createTextField():void {
addChild(my_txt);
addChild(label_txt);
// my_txt.x += 50;
my_txt.autoSize = TextFieldAutoSize.RIGHT;
my_fmt.align = TextFormatAlign.RIGHT;
my_txt.defaultTextFormat = my_fmt;
label_txt.autoSize = TextFieldAutoSize.LEFT;
label_txt.text = "local variable:\nproperty:";
}
private function xTrace(n:int):void {
my_txt.appendText(String(n) + "\n");
}
}
}