Why the first method run is slower than after first run?
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
when play the code, InstanceTest.Update()'s CPU Time is hiccup when execute Test1() and Test2() on first time. Is it cause of Mono JIT? I tried to use RuntimeHelpers.PrepareMethod() on Awake() to preload method but it wasn't work
hiccup.jpg
(74.4 kB)
Comment