V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
UNITY: Game Development Tool
License Comparisons
bakatori
V2EX  ›  UNITY

对于 U3D Stopwatch ElapsedTick 的疑惑

  •  
  •   bakatori · 2020-06-11 21:06:44 +08:00 · 1723 次点击
    这是一个创建于 1387 天前的主题,其中的信息可能已经有所发展或是发生改变。

    记录方法

        static public void time (string key) {
            if (timeKeyHub.ContainsKey (key)) {
                Debug.LogError ("MLOG.cs time key already exist");
            } else {
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch ();
                timeKeyHub.Add (key, sw);
                sw.Start ();
            }
        }
        static public void timeEnd (string key) {
            if (timeKeyHub.ContainsKey (key)) {
                System.Diagnostics.Stopwatch sw;
                timeKeyHub.TryGetValue (key, out sw);
                sw.Stop();
                Debug.Log (string.Format ("<color=blue>{0}</color> {1} ms {2} ticks", key, sw.ElapsedMilliseconds, sw.ElapsedTicks));
                // BIRDTODO:用池子
                sw = null;
                timeKeyHub.Remove (key);
            } else {
                Debug.LogError ("MLOG.cs timeend key not exist");
            }
        }
    

    A*算法的部分代码

        MLOG.time("newCostDealer");
        MLOG.time("newCostDealer - newCost");
        float newCost = cost_so_far[cur]+ heuristic(next.Pos, end.Pos);
        MLOG.timeEnd("newCostDealer - newCost");
    
        MLOG.time("newCostDealer - 0");
        bool tmp2 = !cost_so_far.ContainsKey(next);
        MLOG.timeEnd("newCostDealer - 0");
    
        MLOG.time("newCostDealer - temp3");
        bool tmp3 = false;
        if (!tmp2) {
            tmp3 = newCost < cost_so_far[next];
        }
        MLOG.timeEnd("newCostDealer - temp3");
    
        if (tmp2 || tmp3)
        {
            MLOG.time("newCostDealer - 1");
            frontier.put(next, newCost);
            MLOG.timeEnd("newCostDealer - 1");
    
            MLOG.time("newCostDealer - 2");
            cost_so_far[next] = newCost;
            // MLOG.info("came_from[next] = cur," + next.ToString() + " " + cur.ToString());
            came_from[next] = cur;
            MLOG.timeEnd("newCostDealer - 2");
        }
    
        MLOG.timeEnd("newCostDealer");
    

    运行结果:

    tIfWA1.png

    求教,为啥 newCostDealer ticks 和其它记录加起来差那么多丫?!

    1 条回复    2020-06-11 21:45:23 +08:00
    bakatori
        1
    bakatori  
    OP
       2020-06-11 21:45:23 +08:00
    求教
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2922 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:06 · PVG 22:06 · LAX 07:06 · JFK 10:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.