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

Vector Test

Vectorの生成比較っぽいもの。一部を除いてあまり差はない


[0,1,2,3,4] as Vector.<Number>
はnullなので使えませんでした。
エラーにして欲しい…
Get Adobe Flash player
by zahir 21 Sep 2010
/**
 * Copyright zahir ( http://wonderfl.net/user/zahir )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vHjn
 */

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.utils.getTimer;
    
    /**
     * ...
     * @author zahir
     */
    [SWF(width="465",height="465")]
    public class Main extends Sprite 
    {
        private var t:TextField;
        private var len:int = 100000;
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            addChildAt( (t = new TextField()), 0 );
            t.width = t.height = 465;
            
            addEventListener(MouseEvent.MOUSE_UP, test);
            test();
        }
        private function test(e:MouseEvent = null):void {
            t.text = "vector :: " + $( vec ) + " ms\n";
            t.appendText( "vector2 :: " + $( vec2 ) + " ms\n" );
            t.appendText( "vector3 :: " + $( vec3 ) + " ms\n" );
            t.appendText( "vector4 :: " + $( vec4 ) + " ms\n" );
            t.appendText( "array as vector :: " + $( arrASvec ) + " ms\n" );
            t.appendText( "array 2 vector:: " + $( arr2vec ) + " ms\n" );
        }
        private function $( func:Function):int {
            var time:int = getTimer();
            for (var i:int = 0; i < len; i++ ) {
                func();
            }
            return getTimer() - time;
        }
        private function vec():void {
            var v:Vector.<Number> = new Vector.<Number>();
            v.push(0,1,2,3,4);
        }
        private function vec2():void {
            var v:Vector.<Number> = new Vector.<Number>([0,1,2,3,4]);
        }
        private function vec3():void {
            var v:Vector.<Number> = new <Number>[0,1,2,3,4];
        }
        private function vec4():void {
            var v:Vector.<Number> = new Vector.<Number>(5, false);
            v[0] = 0;
            v[1] = 1;
            v[2] = 2;
            v[3] = 3;
            v[4] = 4;
        }
        private function arrASvec():void {
            var v:Vector.<Number> = [0,1,2,3,4] as Vector.<Number>;
        }
        private function arr2vec():void {
            var v:Vector.<Number> = Vector.<Number>([0,1,2,3,4]);
        }
        
    }
    
}