duck

Communication speed test

Mar 23rd, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class CommunicationTest : PerformanceTest {
  4.  
  5.     GameObject objRef;
  6.     CommTest scriptRef;
  7.    
  8.     public override void Initialise(int caseNumber)
  9.     {
  10.         objRef = new GameObject("communication test object "+caseNumber);
  11.         scriptRef = objRef.AddComponent<CommTest>();
  12.     }
  13.    
  14.     public override void Finish(int caseNumber)
  15.     {
  16.         GameObject.Destroy(objRef);
  17.         objRef = null;
  18.         scriptRef = null;
  19.     }
  20.    
  21.     public override string[] CaseDescriptions {
  22.         get {
  23.             return new string[] {            
  24.                 "SendMessage",
  25.                 "GetComponent",
  26.                 "Direct Call"
  27.             };
  28.         }
  29.     }
  30.  
  31.    
  32.     public override bool Test(int caseNumber)
  33.     {
  34.        
  35.         switch (caseNumber) {
  36.            
  37.             case 0:
  38.                 objRef.SendMessage("TestFunction");
  39.                 break;
  40.            
  41.             case 1:
  42.                 objRef.GetComponent<CommTest>().TestFunction();
  43.                 break;
  44.            
  45.             case 2:
  46.                 scriptRef.TestFunction();
  47.                 break;
  48.         }
  49.         return false;
  50.     }    
  51.    
  52.         public bool ForceOneIteration { get { return false; } }
  53.  
  54. }
  55.  
  56. public class CommTest : MonoBehaviour
  57. {
  58.     int n=0;
  59.    
  60.     public void TestFunction() {
  61.         // do something arbitrary so compiler doesn't get clever and unroll it to nothing!
  62.         n++;
  63.     }
  64.    
  65. }
Advertisement
Add Comment
Please, Sign In to add comment