понедельник, 11 июня 2012 г.

SendMessage vs Realtime Call

Unity3d, C#

gameObject.SendMessage("doTestCall"); vs tpb.doTestCall();



Case 1:


                Debug.Log("Benchmarking 100000 direct vs. 100000 indirect calls.");

float startTime = Time.realtimeSinceStartup;

for (int i = 0; i < 100000; i++)
{
gameObject.SendMessage("doTestCall");
}

Debug.Log("SendMessage took " + (Time.realtimeSinceStartup - startTime).ToString());

startTime = Time.realtimeSinceStartup;

for (int i = 0; i < 100000; i++)
{
TerrainPrefabBrain tpb = gameObject.GetComponent<TerrainPrefabBrain>();
tpb.doTestCall();
}

Debug.Log("Realtime took " + (Time.realtimeSinceStartup - startTime).ToString());

Result case 1:

// SendMessage took 0.05875015
// Realtime took 0.1102734


Case 2:

               Debug.Log("Benchmarking 100000 direct vs. 100000 indirect calls.");

float startTime = Time.realtimeSinceStartup;

for (int i = 0; i < 100000; i++)
{
gameObject.SendMessage("doTestCall");
}

Debug.Log("SendMessage took " + (Time.realtimeSinceStartup - startTime).ToString());

startTime = Time.realtimeSinceStartup;

TerrainPrefabBrain tpb = gameObject.GetComponent<TerrainPrefabBrain>();
for (int i = 0; i < 100000; i++)
{
tpb.doTestCall();
}

Debug.Log("Realtime took " + (Time.realtimeSinceStartup - startTime).ToString());

Result case 2:

// SendMessage took 0.0526247
// Realtime took 0.0009641647



Комментариев нет:

Отправить комментарий