What is the correct way to create FPS counter?

Hi, I’m having a trouble creating FPS counter and I wonder why.

I run this code float fps = 1f/Time.deltaTime in Update(), but the output varies a lot from editor’s stat window (like fps=120, stats=190).

So, unless it’s the editor that’s broken, that doesn’t work, why? (Also, I would like it work with builds, not just editor)

Your calculation is perfectly fine and does give you the correct framerate as long as the framerate is higher than 3 fps (because unity caps deltaTime at 0.3333).

The stats window does not report the actual framerate but concentrate on the graphics performance. So it’s more a summary of the rendering load without any other editor. Have a look at this:

The amount of time taken to process
and render one game frame (and its
reciprocal, frames per second). Note
that this number only includes the
time taken to do the frame update and
render the game view; it does not
include the time taken in the editor
to draw the scene view, inspector and
other editor-only processing.

If you actually use a overlay like fraps which can display an fps counter inside your game window, you will notice that it matches 1/deltaTime