Сравнительная производительность вызова Invoke\Coroutine
Добавлено: 25 май 2011, 19:51
Вот такой маленький тест (на моем PC) .
//Invoke empty method by name, 1000 iterations:
// = 0.555 - 0.6 ms
//Launch empty method directly, 1000 iterations
// = 0.125 ms
//Launch empty cor by name, 1000 iterations
// = 2.5 - 3.6 ms
//Launch empty cor directly, 1000 iterations
// = 1.6 - 1.8 ms
//Invoke empty method by name, 1000 iterations:
// = 0.555 - 0.6 ms
//Launch empty method directly, 1000 iterations
// = 0.125 ms
//Launch empty cor by name, 1000 iterations
// = 2.5 - 3.6 ms
//Launch empty cor directly, 1000 iterations
// = 1.6 - 1.8 ms
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
using System.Diagnostics;
public class PerfTest1 : MonoBehaviour
{
void Start ()
{
Stopwatch stopWatch = Stopwatch.StartNew();
for (int i = 0; i < 1000; i++)
{
//Invoke("Test1", 0f);
//Test1();
//StartCoroutine("Test2");
StartCoroutine(Test2());
}
stopWatch.Stop();
double ms = (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency;
UnityEngine.Debug.Log(string.Concat(ms.ToString(), " ms"));
}
void Test1()
{
}
IEnumerator Test2()
{
yield break;
}
}
using System.Collections;
using System.Diagnostics;
public class PerfTest1 : MonoBehaviour
{
void Start ()
{
Stopwatch stopWatch = Stopwatch.StartNew();
for (int i = 0; i < 1000; i++)
{
//Invoke("Test1", 0f);
//Test1();
//StartCoroutine("Test2");
StartCoroutine(Test2());
}
stopWatch.Stop();
double ms = (stopWatch.ElapsedTicks * 1000.0) / Stopwatch.Frequency;
UnityEngine.Debug.Log(string.Concat(ms.ToString(), " ms"));
}
void Test1()
{
}
IEnumerator Test2()
{
yield break;
}
}