Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- public class PerformanceTests : MonoBehaviour {
- public float testDuration = 5;
- public float iterationsPerFrame = 10000;
- List<int> results;
- IEnumerator Start () {
- Stopwatch stopwatch = new Stopwatch();
- IComparisonTest test = new CommunicationTest();
- for (int caseNum=0; caseNum < test.CaseDescriptions.Length; ++caseNum)
- {
- int numCompleted = 0;
- stopwatch.Reset();
- float testEndTime = Time.time + testDuration;
- test.Initialise();
- UnityEngine.Debug.Log("Testing case "+caseNum+" : "+test.CaseDescriptions[caseNum]);
- // pre-test run
- test.Test(caseNum);
- while (Time.time < testEndTime)
- {
- for (int i = 0; i < iterationsPerFrame; ++i)
- {
- stopwatch.Start();
- test.Test(caseNum);
- stopwatch.Stop();
- numCompleted++;
- }
- yield return null;
- }
- UnityEngine.Debug.Log("Time "+(((float)stopwatch.ElapsedTicks) / numCompleted) +" ticks per test ");
- test.Finish();
- }
- }
- }
- public interface IComparisonTest {
- string[] CaseDescriptions {
- get;
- }
- void Initialise();
- void Finish();
- void Test (int caseNumber);
- }
Advertisement
Add Comment
Please, Sign In to add comment