summaryrefslogtreecommitdiff
path: root/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-18 10:16:32 +0800
committerchai <215380520@qq.com>2023-10-18 10:16:32 +0800
commit4ccd4bc6d126e0e0f51a50aa10c85b9bf48b1210 (patch)
tree9ac931da935b59a8d7c57ff0b6d90b88a0e5a479 /ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs
+ init
Diffstat (limited to 'ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs')
-rw-r--r--ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/Test.cs80
1 files changed, 80 insertions, 0 deletions
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<float, bool> RegularDelegate;
+ public System.Func<float, bool> DynamicDelegate;
+ public Condition condition;
+ public SerializableEvent ev;
+
+ void Start() {
+ RegularDelegate = TestMethod;
+ DynamicDelegate = (System.Func<float, bool>) System.Delegate.CreateDelegate(typeof(System.Func<float, bool>), 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<float, bool> { } \ No newline at end of file