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

Shift Unshift おもすぎ!!

bkzenさんのつぶやきを受けてテスト
Get Adobe Flash player
by keno42 11 Aug 2009
/**
 * Copyright keno42 ( http://wonderfl.net/user/keno42 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5Ig6
 */

// bkzenさんのつぶやきを受けてテスト
// forked from beinteractive's forked from: 関数のオーバーヘッドありすぎない?
// forked from keno42's 関数のオーバーヘッドありすぎない?
package {
    import flash.display.Sprite;
    import flash.text.*;
    import flash.utils.*;
    public class FlashTest extends Sprite {
        private static const COUNT:uint = 20000;
        private var array:Array = [];
        private var tf:TextField = new TextField();
        public function FlashTest() {
            // write as3 code here..
            addChild(tf);
            tf.autoSize = "left";
            testReverse();
            testPush();
            testReverse();
            testPush();
            testReverse();
            testPush();
            testReverse();
            testPop();
            testPop();
            testPop();
            testUnshift();
            testUnshift();
            testUnshift();
            testShift();
            testShift();
            testShift();
            testOriginalUnshift();
        }
        private function testPush():void
        {
            var time:uint = getTimer();
            var i:Number, j:Number;
            for( i=0; i < COUNT; i++ ){
                array.push(i);
            }
            tf.appendText("push(配列長" + (array.length-COUNT) +"->"+ array.length+ "): " + String(getTimer()-time) + "\n");
        }
        private function testPop():void
        {
            var time:uint = getTimer();
            var i:Number, j:Number;
            for( i=0; i < COUNT; i++ ){
                array.pop();
            }
            tf.appendText("pop(配列長" + (array.length+COUNT) +"->"+ array.length+ "): " + String(getTimer()-time) + "\n");
        }
        private function testReverse():void
        {
            var time:uint = getTimer();
            var i:Number, j:Number;
            for( i=0; i < (COUNT/100); i++ ){
                array.reverse();
            }
            tf.appendText("reverse(配列長" + array.length+ "を"+(COUNT/100)+"回): " + String(getTimer()-time) + "\n");
        }
        private function testShift():void
        {
            var time:uint = getTimer();
            var i:Number, j:Number;
            for( i=0; i < COUNT; i++ ){
                array.shift();
            }
            tf.appendText("shift(配列長"+ (array.length+COUNT) +"->" + array.length+ "): " + String(getTimer()-time) + "\n");
        }
        private function testUnshift():void
        {
            var time:uint = getTimer();
            var i:Number, j:Number;
            for( i=0; i < COUNT; i++ ){
                array.unshift(1);
            }
            tf.appendText("unshift(配列長"+ (array.length-COUNT) +"->" + array.length+ "): " + String(getTimer()-time) + "\n");
        }
        private function testOriginalUnshift():void
        {
            var time:uint = getTimer();
            var i:Number, j:Number;
            array.reverse();
            for( i=0; i < COUNT; i++ ){
                array.push(i);
            }
            array.reverse();
            tf.appendText("自作unshift(配列長"+ (array.length-COUNT) +"->" + array.length+ "): " + String(getTimer()-time) + "\n");
        }
    }
}