- Home /
FPS Measurement Issue
Hey, so I'm trying to measure the average FPS of my game over a period of about 10 seconds, so that I can test performance. My issue is that I can't get a solid reading of the average FPS. I have a script that takes the time using Unity's Time functions, and also takes it using C# stopwatch mechanism, and ALSO takes the sum of all frame execution times (Time.deltaTime) and divides the total frame count by that time. At the end of the period, I divide my Unity time and my system time numbers by the total number of frames rendered, and print my results to the console. But none of my numbers are consistent.
Firstly, here's my script: using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Diagnostics;
public class TimeTaker : MonoBehaviour { Stopwatch sw;
float frameTime = 0f;
float initialFramTime = 0f;
// Use this for initialization
void Start () {
sw = new Stopwatch();
}
// Update is called once per frame
void Update () {
frameTime += Time.deltaTime;
if(Time.frameCount == 1)
{
sw.Start();
//Catch the time of execution for the first frame
initialFramTime += Time.deltaTime;
}
if(Time.time > 10f && Time.time < 11f)
{
sw.Stop();
UnityEngine.Debug.Log("Time.time = " + Time.time);
UnityEngine.Debug.Log("Stopwatch time = " + (sw.Elapsed.TotalSeconds + (double)initialFramTime));
UnityEngine.Debug.Log("Unity FPS estimate = " + (Time.frameCount / Time.time));
UnityEngine.Debug.Log("Stopwatch FPS estimate = " + (Time.frameCount / (sw.Elapsed.TotalSeconds + (double)initialFramTime)));
UnityEngine.Debug.Log("Manually Count Frame Time FPS Estimate = " + (Time.frameCount / frameTime));
}
}
}
And here are my results:
Additionally, all of these numbers differ from the FPS printed by the stats window,
The reason I do this is because it seems like the Unity internal time measure becomes really innacurate when games run slowly, but I still want to measure an accurate FPS when the game is running slowly.
So what's going on? Which number do I trust?
EDIT: Here's an example of the same results when the FPS is really struggling: (No more attachments allowed but here's text)
Time.time = 10.02
Stopwatch time = 41.347346799553
Unity FPS estimate = 50.0998
Stopwatch FPS estime = 12.1410450453722
Manually Count Frame Time FPS Estimate = 49.9998
Stats window reading a normal FPS around 18.5 FPS
Your answer
Follow this Question
Related Questions
How can I track disassembly code back to a script? 0 Answers
Properly debug Gear VR apps 1 Answer
Is it just me, or does debug log crash unity on large iterations? 1 Answer
How to use Webgl Debug Symbols? 0 Answers
How to lock FPS? 1 Answer