#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í)間
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。