Skip to content

Instantly share code, notes, and snippets.

@phi-lira
Created March 16, 2018 18:02
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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