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?
Good question. I've noticed times when the Stats window claims fps of 50+ but I could watch the screen and count the frames as they go by. The Stats window tries to factor out the overhead of the editor running and so forth, but it often seems over-optimistic about how fast my game is running.
Answer by skovacs1
Nov 09, 2010 at 07:44 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.
Answer by Eric5h5
Nov 09, 2010 at 08:14 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.
Maybe I don't get it, but after a small test I'm pretty sure that the stats window definetly takes into account more than just the draw time for graphics. If you insert some stupid but lengthy loop into your update you can see the fps in the stats window drop.
Also I know that I have a lot of overhead using the editor and profiler (let alone deep profiling), but I am confused why the profiler reports a much HIGHER fps. Does it try to predict the times and frame rate that I could expect in a build version?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
No one has followed this question yet.
Device.Present creates huge freezes
Why is there difference in fps and time to render a frame in statistics window and profiler?
RenderTexture.SetActive causing performance issue. android profiler
Terrible Lag When Starting a Scene Which Eventually Resolves Itself... Graphics Card Issue or Unity?
Windows Phone 8 Overhead - Crawling