[英]c# method first run is slower than after first run
I made this code 我写了这段代码
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;
}
}
On Profiler 在探查器上
enter image description here 在此处输入图片说明
why CPU Time on Update() hiccup when call Test1() and Test2() at first time? 第一次调用Test1()和Test2()时,为什么Update()上的CPU时间会打ic?
There's probably some JIT (Just In Time) compilation happening during the first call of the functions. 在第一次调用函数期间,可能会发生一些JIT(Just In Time)编译。
The second and subsequent times the functions are called, there's an optimized version of them waiting. 第二次及之后的函数调用,有一个优化的版本等待。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.