测试代码会用到的基类
using System; using UnityEngine; public abstract class CollideTestBase : MonoBehaviour { [Range(0, 1)] public int m_ApiType = 1; [Range(1, 3000000)] public int m_InvokeCount = 1; //用于测试多次调用时的耗时 public bool m_Benchmark = false; //测试调用多少次时, 执行耗时超过800ms public bool m_ShowLog = false; protected bool m_IsIntersect = false; protected void CheckTimeCost(DateTime t1, int maxApiCount) { var t2 = DateTime.Now; double totalMs = (t2 - t1).TotalMilliseconds; if (m_Benchmark || m_ShowLog) Debug.Log($"type:{m_ApiType}, count:{m_InvokeCount}, totalMs:{totalMs}"); if (totalMs >= 1000) //防止卡住 m_InvokeCount /= 10; if (m_Benchmark) { if (totalMs >= 800) { if (m_ApiType >= maxApiCount) { m_ApiType = 1; m_InvokeCount = 1; m_Benchmark = false; } else m_ApiType++; } else { double multi = 800 / totalMs; if (multi >= 2) m_InvokeCount = (int)(m_InvokeCount * 2); else if (multi > 1) m_InvokeCount = (int)(m_InvokeCount * multi); else m_InvokeCount++; } } } }
标签:false,CollideTestBase,int,InvokeCount,ApiType,totalMs,public From: https://www.cnblogs.com/sailJs/p/17854070.html