In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: Vector class versus Array class

/**
 * Copyright gyo ( http://wonderfl.net/user/gyo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/oU1R
 */

// 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 = 5000000;
        private var my_array:Array = new Array();
        private var myVector:Vector.<int> = new Vector.<int>();
        private var myVectorFixed:Vector.<int> = new Vector.<int>(MAX_NUMBER,true);
        private var i:int;
        private var started:int;
        public function Vector_vs_Array() {
            testArray();
            testVector();
            testVectorFixed();
                        // TextField for display
            addChild(my_txt);
                        addChild(label_txt);
                        my_txt.x += 80;
                        label_txt.text = "Array:\nVector:\nVector (fixed):";
        }
        private function testArray():void {
            started = getTimer();
            for (i = 0; i < MAX_NUMBER; i++) {
                my_array[i] = 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 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");
        }
    }
}