Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Performance Tracker scripts.
// 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