From 4ccd4bc6d126e0e0f51a50aa10c85b9bf48b1210 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 18 Oct 2023 10:16:32 +0800 Subject: + init --- .../SerializableCallback/Runtime/Test.cs | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs (limited to 'ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs') diff --git a/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs b/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs new file mode 100644 index 0000000..2c258ba --- /dev/null +++ b/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs @@ -0,0 +1,80 @@ +using System; +using System.Diagnostics; +using UnityEngine; + +public class Test : MonoBehaviour { + const int ITERATIONS = 100000; + public float f = 0.5f; + public string s; + public System.Func RegularDelegate; + public System.Func DynamicDelegate; + public Condition condition; + public SerializableEvent ev; + + void Start() { + RegularDelegate = TestMethod; + DynamicDelegate = (System.Func) System.Delegate.CreateDelegate(typeof(System.Func), this, "TestMethod"); + condition.Invoke(f); + } + + void Update() { + var method = Stopwatch.StartNew(); + bool methodb = false; + for (int i = 0; i < ITERATIONS; ++i) { + methodb = TestMethod(f); + } + method.Stop(); + + var regularDelegate = Stopwatch.StartNew(); + bool regularDelegateb = false; + for (int i = 0; i < ITERATIONS; ++i) { + regularDelegateb = RegularDelegate(f); + } + regularDelegate.Stop(); + + var dynamicDelegate = Stopwatch.StartNew(); + bool dynamicDelegateb = false; + for (int i = 0; i < ITERATIONS; ++i) { + dynamicDelegateb = DynamicDelegate(f); + } + dynamicDelegate.Stop(); + + var serializedDelegate = Stopwatch.StartNew(); + bool serializedDelegateb = false; + for (int i = 0; i < ITERATIONS; ++i) { + serializedDelegateb = condition.Invoke(f); + } + serializedDelegate.Stop(); + + var serializedEvent = Stopwatch.StartNew(); + for (int i = 0; i < ITERATIONS; ++i) { + ev.Invoke(); + } + serializedEvent.Stop(); + + UnityEngine.Debug.Log("Method: " + methodb + method.Elapsed); + UnityEngine.Debug.Log("RegularDelegate: " + regularDelegateb + regularDelegate.Elapsed); + UnityEngine.Debug.Log("DynamicDelegate: " + dynamicDelegateb + dynamicDelegate.Elapsed); + UnityEngine.Debug.Log("SerializedCallback: " + serializedDelegateb + serializedDelegate.Elapsed); + UnityEngine.Debug.Log("SerializedEvent: " + serializedEvent.Elapsed); + } + + public bool TestMethod(float f) { + return f > 0.5f; + } + + public bool TestMethod(string a) { + return string.IsNullOrEmpty(a); + } + + public bool TestMethod2(float f, string a) { + return f > 0.5f && string.IsNullOrEmpty(a); + } + + public void TestMethod2(string a) { + s = a; + } +} + +[Serializable] +public class Condition : SerializableCallback { } \ No newline at end of file -- cgit v1.1-26-g67d0