日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

【Unity3D之獲取某個(gè)方法執(zhí)行的時(shí)間】

 鴻蛟家平 2016-05-19
    #region 計(jì)算代碼執(zhí)行花費(fèi)的時(shí)間
    //如果要用納秒級(jí)或微秒級(jí)的話 就多測(cè)幾次取平均

    #region 納秒級(jí)10-9秒
    public static void calculate_cudetime_namiao(this MonoBehaviour mono, string methodname)
    {
        Type t = mono.GetType();

        MethodInfo vMethodInfo = t.GetMethod(methodname);
        if (vMethodInfo == null) return;

        PerformanceTimer timer = new PerformanceTimer();
        timer.Start();
        vMethodInfo.Invoke(mono, null);
        timer.Stop();

        MyDebug.Log(methodname + " 使用時(shí)間納秒  " + timer.Duration * 1000000000);
    }

    public static void calculate_cudetime_namiao(this MonoBehaviour mono, string methodname, object pram1)
    {
        Type t = mono.GetType();

        MethodInfo vMethodInfo = t.GetMethod(methodname, new Type[] { pram1.GetType() });
        if (vMethodInfo == null) return;

        PerformanceTimer timer = new PerformanceTimer();
        timer.Start();
        vMethodInfo.Invoke(mono, new object[] { pram1 });
        timer.Stop();

        MyDebug.Log(methodname + " 使用時(shí)間納秒  " + timer.Duration * 1000000000);
    }

    public static void calculate_cudetime_namiao(this MonoBehaviour mono, string methodname, object pram1, object pram2)
    {
        Type t = mono.GetType();
        Type p1 = pram1.GetType();
        Type p2 = pram2.GetType();
        MethodInfo vMethodInfo = t.GetMethod(methodname, new Type[] { pram1.GetType(), pram2.GetType() });
        if (vMethodInfo == null) return;
        PerformanceTimer timer = new PerformanceTimer();
        timer.Start();
        vMethodInfo.Invoke(mono, new object[] { pram1, pram2 });
        timer.Stop();

        MyDebug.Log(methodname + " 使用時(shí)間納秒  " + timer.Duration * 1000000000);
    }

    #endregion  納秒級(jí)10-9秒


    #region 微秒級(jí)10-6秒
    public static void calculate_cudetime_weimiao(this MonoBehaviour mono, string methodname)
    {
        Type t = mono.GetType();

        MethodInfo vMethodInfo = t.GetMethod(methodname);
        if (vMethodInfo == null) return;

        PerformanceTimer timer = new PerformanceTimer();
        timer.Start();
        vMethodInfo.Invoke(mono, null);
        timer.Stop();

        MyDebug.Log(methodname + " 使用時(shí)間微秒  " + timer.Duration * 1000000);
    }

    public static void calculate_cudetime_weimiao(this MonoBehaviour mono, string methodname, object pram1)
    {
        Type t = mono.GetType();

        MethodInfo vMethodInfo = t.GetMethod(methodname, new Type[] { pram1.GetType() });
        if (vMethodInfo == null) return;

        PerformanceTimer timer = new PerformanceTimer();
        timer.Start();
        vMethodInfo.Invoke(mono, new object[] { pram1 });
        timer.Stop();

        MyDebug.Log(methodname + " 使用時(shí)間微秒  " + timer.Duration * 1000000);
    }

    public static void calculate_cudetime_weimiao(this MonoBehaviour mono, string methodname, object pram1, object pram2)
    {
        Type t = mono.GetType();
        Type p1 = pram1.GetType();
        Type p2 = pram2.GetType();
        MethodInfo vMethodInfo = t.GetMethod(methodname, new Type[] { pram1.GetType(), pram2.GetType() });
        if (vMethodInfo == null) return;
        PerformanceTimer timer = new PerformanceTimer();
        timer.Start();
        vMethodInfo.Invoke(mono, new object[] { pram1, pram2 });
        timer.Stop();

        MyDebug.Log(methodname + " 使用時(shí)間微秒  " + timer.Duration * 1000000);
    }

    #endregion 微秒級(jí)10-6秒

    #region 毫秒級(jí)10-3秒

    public static void calculate_cudetime(this MonoBehaviour mono, string methodname)
    {
        Type t = mono.GetType();

        MethodInfo vMethodInfo = t.GetMethod(methodname);
        if (vMethodInfo == null) return;
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        vMethodInfo.Invoke(mono, null);
        stopWatch.Stop();

        MyDebug.Log(methodname + "   " + stopWatch.ElapsedMilliseconds);
    }

    public static void calculate_cudetime(this MonoBehaviour mono, string methodname, object pram1)
    {
        Type t = mono.GetType();

        MethodInfo vMethodInfo = t.GetMethod(methodname, new Type[] { pram1.GetType() });
        if (vMethodInfo == null) return;
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        vMethodInfo.Invoke(mono, new object[] { pram1 });
        stopWatch.Stop();

        MyDebug.Log(methodname + "  " + stopWatch.ElapsedMilliseconds);
    }

    public static void calculate_cudetime(this MonoBehaviour mono, string methodname, object pram1, object pram2)
    {
        Type t = mono.GetType();
        Type p1 = pram1.GetType();
        Type p2 = pram2.GetType();
        MethodInfo vMethodInfo = t.GetMethod(methodname, new Type[] { pram1.GetType(), pram2.GetType() });
        if (vMethodInfo == null) return;
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        vMethodInfo.Invoke(mono, new object[] { pram1, pram2 });
        stopWatch.Stop();

        MyDebug.Log(methodname + "   " + stopWatch.ElapsedMilliseconds);
    }

    /*
     調(diào)用事例  必須是公有方法
     *
     public void fun(int a)
     * {
       }
     * update()
     * {
       if (Input.GetKeyDown(KeyCode.Space))
        {
         //   calculate("Call");

       this.calculate_cudetime("fun",10)
        }
     * }

     */

    #endregion 毫秒級(jí)10-3秒

    #endregion 計(jì)算代碼執(zhí)行花費(fèi)的時(shí)間

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多