Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jessespike · Oct 03, 2012 at 05:37 AM · fpstimecalculateframe rateaverage

How to calculate an average frame rate

I made a simple FPS monitor script. It displays the current frame rate, as well keeps track of the lowest and highest numbers. I plan on keeping track of the average FPS for each level. My question is how do I calculate the average frame rate?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Oct 03, 2012 at 08:06 AM 0
Share

well to find an average, count say 1000 frames and notice how long it took.

You then need to use division.

Also -

http://docs.unity3d.com/Documentation/ScriptReference/Time.html

notice frameCount

FYI

http://docs.unity3d.com/Documentation/ScriptReference/Application-targetFrameRate.html

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Oct 03, 2012 at 05:45 AM

An approximate calculation can be done with:

 print(1/Time.deltaTime);


EDIT: Well, this is not approximate at all, this is the value. If you have been through some oscillations and waves topics, deltaTime is T or period which is the time between two peaks of the wave calculated in second. fps is the frequency f which is the amount of peaks in 1 second calculated in Hertz(Hz) and the relation with T is:

 f = 1/T;
 T = 1/f;

In our case a peak is a frame starting.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessespike · Oct 03, 2012 at 06:23 AM 0
Share

yeah, I wanted the average of all the values. Currently I'm thinking of recording each frame and dividing the total time played in each level. I was thinking there was a better way... To calculate the average right now, it would look like:

28800 frames / 1200 seconds = 24

I guess, now that I look at it, this method isn't so bad. Thanks.

avatar image fafase · Oct 03, 2012 at 09:56 AM 0
Share

What you are looking for then for average is there:

http://docs.unity3d.com/Documentation/ScriptReference/Time-realtimeSinceStartup.html

It says:

 // A FPS counter.
 // It calculates frames/second over each updateInterval,
 // so the display does not keep changing wildly.
avatar image
8

Answer by AnomalusUndrdog · Oct 10, 2013 at 11:30 PM

It's called Moving Average. The cumulative type of moving average is what you probably want. It's the average of all values up to the current one.

A brute force approach is to collect all fps values since the beginning and continually making an average of all of them. But through math, you can simplify the formula such that you don't need to collect the values anymore. You just keep the current average and how many have been averaged so far, and use some math to get the new one.

Check the wikipedia article linked for details.

Take note you still need to compute the FPS yourself using other means. What this does is only make an average of all FPS values so far.

 int qty = 0;
 float currentAvgFPS = 0;
 
 float UpdateCumulativeMovingAverageFPS(float newFPS)
 {
     ++qty;
     currentAvgFPS += (newFPS - currentAvgFPS)/qty;
 
     return currentAvgFPS;
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by Marrt · Nov 13, 2016 at 07:37 PM

This is how i do it, it is far easier than anything else, no cumulative stuff, just one float

 float avg    = 0F; //declare this variable outside Update
 //run this in Update()
   avg += ((Time.deltaTime/Time.timeScale) - avg) * 0.03f; //run this every frame
   float displayValue = (1F/avg); //display this value

The good thing about this is that past values gradually fade out of importance, so it is not to jittery and not to slow

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Oneiros90 · Dec 02, 2019 at 04:26 PM 0
Share

I find this answer better than the one provided by @AnomalusUndrdog: his solution will always take into account past values and new values will have smaller and smaller importance, resulting in a not accurate framerate

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Real elapsed time since frame begin 1 Answer

How can I make a GUI element move independently of the frame rate? 1 Answer

Framerate counter 1 Answer

How to calculate the amount of Change of Position.Y for a certain amount of time. 0 Answers

My Character lags when moving, when i have a custom made blender model what should i do? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges