You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
1.8 KiB
93 lines
1.8 KiB
using UnityEngine; |
|
using System; |
|
using System.Collections; |
|
|
|
public class PK2 : MonoBehaviour |
|
{ |
|
const int LoopNumber = 500; |
|
|
|
Action<string> action; |
|
|
|
bool isStartDelegate; |
|
bool isStartSendMessage; |
|
|
|
int count; |
|
|
|
private ProfilerTest profiler; |
|
private long time0; |
|
private long time1; |
|
|
|
void Start() |
|
{ |
|
profiler = new ProfilerTest(); |
|
|
|
action += Funciton1; |
|
} |
|
|
|
void Update() |
|
{ |
|
if (isStartDelegate) |
|
{ |
|
profiler.Start(); |
|
|
|
for (var i = 0; i < LoopNumber; ++i) |
|
if (action != null) |
|
action(""); |
|
|
|
profiler.Stop(); |
|
|
|
time0 += profiler.ElapsedTicks; |
|
|
|
if (count == LoopNumber) |
|
isStartDelegate = false; |
|
} |
|
|
|
if (isStartSendMessage) |
|
{ |
|
profiler.Start(); |
|
|
|
for (var i = 0; i < LoopNumber; ++i) |
|
this.gameObject.SendMessage("Funciton2", "", SendMessageOptions.DontRequireReceiver); |
|
|
|
profiler.Stop(); |
|
|
|
time1 += profiler.ElapsedTicks; |
|
|
|
if (count == LoopNumber) |
|
isStartSendMessage = false; |
|
} |
|
} |
|
|
|
|
|
void OnGUI() |
|
{ |
|
if (GUILayout.Button("INVOKE Delegate")) |
|
{ |
|
isStartDelegate = true; |
|
|
|
time0 = 0; |
|
count = 0; |
|
} |
|
|
|
if (GUILayout.Button("SendMessage")) |
|
{ |
|
isStartSendMessage = true; |
|
|
|
time1 = 0; |
|
count = 0; |
|
} |
|
|
|
GUILayout.Label("Delegate Time: " + TimeSpan.FromTicks(time0).TotalMilliseconds.ToString() + " ms"); |
|
GUILayout.Label("U3D SendMessage Time: " + TimeSpan.FromTicks(time1).TotalMilliseconds.ToString() + " ms"); |
|
} |
|
|
|
void Funciton1(string s) |
|
{ |
|
count++; |
|
} |
|
|
|
void Funciton2(string s) |
|
{ |
|
count++; |
|
} |
|
}
|
|
|