package {
import flash.display.*;
import flash.text.*;
import flash.utils.getTimer;
import flash.utils.ByteArray;
public class FlashTest extends Sprite {
private var iterations:int = 10000;
private var items:int = 100;
private var str:String = "/tuio/obj2D";
private var ba:ByteArray = new ByteArray();
private var tf:TextField = new TextField;
public function FlashTest() {
// write as3 code here..
tf.width = stage.stageWidth;
tf.height = stage.stageHeight;
tf.text = "Performance:";
addChild( tf );
tf.appendText("\nlinkedlist: "+linkedListAdd().toString());
tf.appendText("\nvector: "+vectorAdd().toString());
tf.appendText("\narray: "+arrayAdd().toString());
}
public function linkedListAdd():int{
var i:int = 0;
var v:LinkedList;
var s:Sprite;
var it:Item;
v = new LinkedList();
for(var o:int = 0; o < items; o++){
v.push(new Sprite());
}
var start:int = getTimer();
for(var k:int = 0; k < iterations; k++){
while(it = v.next()){
s = it.value as Sprite;
}
v.reset();
}
return (int(getTimer()) - start);
}
public function vectorAdd():int{
var i:int = 0;
var v:Vector.<Object>;
var s:Sprite;
var st:Sprite;
v = new Vector.<Object>();
for(var o:int = 0; o < items; o++){
v.push(new Sprite());
}
var start:int = getTimer();
for(var k:int = 0; k < iterations; k++){
for each(var sp:Sprite in v){
st = sp;
}
}
return (int(getTimer()) - start);
}
public function arrayAdd():int{
var i:int = 0;
var v:Array;
var s:Sprite;
var st:Sprite;
v = new Array();
for(var o:int = 0; o < items; o++){
v.push(new Sprite());
}
var start:int = getTimer();
for(var k:int = 0; k < iterations; k++){
for each(var sp:Sprite in v){
st = sp;
}
i = 0;
}
return (int(getTimer()) - start);
}
}
}
class LinkedList {
import flash.display.*;
private var root:Item;
private var current:Item;
private var last:Item;
public function LinkedList():void{
root = new Item(null);
last = root;
current = root;
}
public function push(value:Object):void{
last = last.right = new Item(value);
}
public function next():Item{
return current = current.right;
}
public function reset():void{
current = root;
}
}
class Item {
import flash.display.*;
public var right:Item;
public var value:Object;
public function Item(value:Object):void{
this.value = value;
}
}