/**
* Copyright fltst ( http://wonderfl.net/user/fltst )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/slGA
*/
// forked from fltst's forked from: Vector class versus Array class
// forked from Fumio's Vector class versus Array class
package {
import flash.display.Sprite;
import flash.utils.getTimer;
import flash.text.TextField;
[SWF(width = "240", height = "180")]
public class Vector_vs_Array extends Sprite {
private static var my_txt:TextField = new TextField();
private static var label_txt:TextField = new TextField();
private const MAX_NUMBER:int = 1000000;
private var my_array:Array = new Array();
private var my_arrayp:Array = new Array();
private var myVector:Vector.<int> = new Vector.<int>();
private var myVectorP:Vector.<int> = new Vector.<int>();
private var myVectorFixed:Vector.<int> = new Vector.<int>(MAX_NUMBER,true);
private var i:int;
private var started:int;
private var tmp:int;
public function Vector_vs_Array() {
testArray();
testArrayPush();
testVector();
testVectorPush();
testVectorFixed();
// TextField for display
addChild(my_txt);
addChild(label_txt);
my_txt.x += 80;
label_txt.text = "Array:\nArray(push):\nVector:\nVector(push):\nVector (fixed):";
}
private function testArray():void {
started = getTimer();
for (i = 0; i < MAX_NUMBER; i++) {
my_array[i] = i;
}
xTrace(getTimer() - started);
}
private function testArrayPush():void {
started = getTimer();
for (i = 0; i < MAX_NUMBER; i++) {
my_arrayp.push(i);
}
xTrace(getTimer() - started);
}
private function testVector():void {
started = getTimer();
for (i = 0; i < MAX_NUMBER; i++) {
myVector[i] = i;
}
xTrace(getTimer() - started);
}
private function testVectorPush():void {
for (i = 0; i < MAX_NUMBER; i++) {
myVectorP.push(i);
}
started = getTimer();
for (i = 0; i < MAX_NUMBER; i++) {
myVectorP.push(i);
myVectorP.pop();
}
xTrace(getTimer() - started);
}
private function testVectorFixed():void {
started = getTimer();
for (i = 0; i < MAX_NUMBER; i++) {
myVectorFixed[i] = i;
}
xTrace(getTimer() - started);
}
private static function xTrace(n:int):void {
my_txt.appendText(String(n) + "\n");
}
}
}