Created
March 16, 2018 18:02
-
-
Save phi-lira/580bd64b07fe2f6a597bffdb4e08cac4 to your computer and use it in GitHub Desktop.
Performance Tracker scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Script made by aleks01010101 | |
// Slightly modified | |
// Displays avg and median ms + frames sampled during clipLenght | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PerfTracker : MonoBehaviour { | |
public float clipLength = 20.0f; | |
float elapsed = 0.0f; | |
float duration = 0.0f; | |
int frames = 0; | |
List<float> msData = new List<float>(); | |
// Update is called once per frame | |
void Update () { | |
float dt = Time.deltaTime; | |
if (elapsed >= clipLength) | |
{ | |
if (duration >= clipLength) | |
{ | |
float averageFps = frames / duration; | |
float averageMs = 1000.0f * duration / frames; | |
msData.Sort(); | |
float[] msArray = msData.ToArray(); | |
Debug.LogError("AVG FPS: " + averageFps.ToString() + ", AVG MS: " + averageMs.ToString()); | |
float medMs = msArray[msArray.Length / 2]; | |
float medFps = 1.0f / medMs; | |
medMs *= 1000.0f; | |
Debug.LogError("MED FPS: " + medFps.ToString() + ", MED MS: " + medMs.ToString()); | |
Application.Quit(); | |
} | |
msData.Add(dt); | |
duration += dt; | |
++frames; | |
} | |
elapsed += dt; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment