【发布时间】:2018-08-09 10:04:04
【问题描述】:
我编写了这段代码
using UnityEngine;
public class InstanceTest : MonoBehaviour {
public int cnt; public bool startTest1 = false; public bool startTest2 = false;
void Update()
{
if (startTest1)
Test1(cnt);
if (startTest2)
Test2(cnt);
}
void Test1(int cnt)
{
float a;
for (int i = 0; i < cnt; i++)
a = 1f + 1f;
}
static void Test2(int cnt)
{
float a;
for (int i = 0; i < cnt; i++)
a = 1f + 1f;
}
}
在探查器上
为什么在第一次调用 Test1() 和 Test2() 时 CPU Time on Update() 打嗝?
【问题讨论】:
-
是什么让你觉得第一次比较慢?
-
@mjwills 我使用 RuntimeHelpers.PrepareMethod() 像链接的答案,但仍然打嗝...