forked from: flash on 2012-7-24

by shohei909 forked from flash on 2012-7-24 (diff: 34)
import flash.display.Sprite;

...
@author jc at bkzen
♥0 | Line 96 | Modified 2012-07-24 18:16:30 | MIT License
play

ActionScript3 source code

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

// forked from bkzen's flash on 2012-7-24
package{
    import com.actionscriptbible.Example;
    //import flash.display.Sprite;
    import flash.utils.getTimer;
    /**
     * ...
     * @author jc at bkzen
     */
    public class Test116 extends Example
    //public class Test116 extends Sprite
    {
        
        public function Test116(){
            var L: int = 1000000;
            
            ( function fa(n: int): void {
                trace( "i:" + i );
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++){
                    t++;
                }
                trace("a", getTimer() - j);
            } )(L);
            
            var b: Function = function fb(n: int): void {
                trace( "i:" + i );
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++){
                    t++ ;
                } 
                trace("b", getTimer() - j);
            };
            b(L);
            
            var c: Hoge = new Hoge( function fc(n: int): void {
                trace( "i:" + i );
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++)  
                {
                    t++ ;
                } 
                trace("c", getTimer() - j);
            } );
            c._f(L);
            
            var d: Hoge = new Hoge(null);
            d._f = function(n: int): void{
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++)  
                {
                    t++ ;
                } 
                trace("d", getTimer() - j);
            };
            d._f(L);
            
            
            var e: Hoge = new Hoge(null);
            e.test(function(n: int): void{
                trace( "i:" + i );
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++)  
                {
                    t++ ;
                } 
                trace("e", getTimer() - j);
            });
            e._f(L);
            
            test(function(n: int): void {
                trace( "i:" + i );
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++)  
                {
                    t++ ;
                } 
                trace("f", getTimer() - j);
            }, L);
            
            var g: Hoge = Hoge.create( function(n: int): void {
                trace( "i:" + i );
                var i: int, t: int = 0;
                var j: int = getTimer();
                for (i = 0; i < n; i++){
                    t++ ;
                } 
                trace("g", getTimer() - j);
            });
            g._f(L);
        }
        
        private function test(f: Function, L: int):void {
            f(L);
        }
    }
}

class Hoge{
    public var _f: Function;
    function Hoge(f: Function) { _f = f; }
    public function test(f: Function): void { _f = f; }
    
    public static function create(f: Function): Hoge{
        var h: Hoge = new Hoge(null);
        h._f = f;
        return h;
    }
}