Skip to content

Instantly share code, notes, and snippets.

@gapspt
Last active February 24, 2025 11:00
Show Gist options
  • Select an option

  • Save gapspt/2d89faaf4863407c3e35c80dee6b1bb9 to your computer and use it in GitHub Desktop.

Select an option

Save gapspt/2d89faaf4863407c3e35c80dee6b1bb9 to your computer and use it in GitHub Desktop.
Quick and dirty way to count frames per second (FPS) on Unity
using UnityEngine;
public class FpsCounter : MonoBehaviour
{
float prev = -1;
float fps = 0;
void Update()
{
var now = Time.realtimeSinceStartup;
if (prev >= 0)
{
float fpsNow = 1 / Mathf.Max(0.001f, (now - prev));
fps += (fpsNow - fps) * 0.05f;
}
prev = now;
if (Time.frameCount % 100 == 0)
{
Debug.Log("FPS: " + fps);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment