I tried to profile my game and at the moment Im a bit confused about whick values to trust.
The stats window in my game view reports 140fps. Time.deltaTime is somewhere around 0.02 on average, which would mean 50fps. The profiler reports a few spikes (GC etc.), but on average the frame rate reported by the profiler should be around 1000fps.
So which one should I trust, and why do I get all those different reports?
asked Nov 09 '10 at 05:16 PM
This is an interesting question and I wish I had the definitive answer as to which to trust, but the truth is that none of them is 100% correct.
The stats window is likely closest for something like fps, but it's quite hard to say. Time.deltaTime should be the most accurate, but the overhead of writing out the values changes the results. The profiler's estimate for fps is too generous.
One of the reasons that you get three different values has to do with where the values are coming from, especially if all three are happening simultaneously. Bear in mind that all of these stats are running in the editor which also incurs some overhead that the stats window and profiler will try to accomodate for.
The stats window is a rough approximation of what's really happening in the game view to try and give you an idea of what the run-time performance of the scene is going to be at, but you shouldn't trust it as definitive because it is often wrong (try working out the draw calls for example).
Time.deltaTime is giving you representative values of what is actually happening. This is accurate, but since you are running in the editor, this value is likely less than Unity predicts your run-time to be. Moreover, if you only write to the log for this test case as opposed to writing it for all three, it would even further offset the values as writing to the log is apparently not cheap (I've actually been able to pretty much freeze Unity with some for loops that just write to the log).
The profiler is going to try and guesstimate what it thinks your final run-time fps will be at. This is very off because simply running the profiler eats a lot of memory in and of itself, affecting the results so it must predict to a fair degree. For things other than fps, the profiler should be fairly accurate.
answered Nov 09 '10 at 07:44 PM
The stats window tells you how long it takes to draw the graphics. This is only sort of related to how fast your game actually runs in terms of frames per second, because it's totally ignoring everything else. It's not a matter of "which is more accurate" than the profiler, since it's two quite different pieces of information altogether.
In any case, the editor has a lot of overhead that's not present when running a build on its own, so for truly accurate fps info, you should use this script in an actual build.
answered Nov 09 '10 at 08:14 PM