Search Unity

performance strange issue

Discussion in 'Unity Cloud Diagnostics' started by grobonom, Jul 1, 2018.

  1. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    Hi.

    I'm stuck with a question. When running my scene in editor play mode, the stats say i got 120ish
    fps....
    it appears the stats are lying :eek:
    when i physically measure the frame rate i'm about at the half stats say !!!
    and disabling VSYNC is useless.....
    here's my simple code for fps measurement:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class FPSCounter : MonoBehaviour {
    6.  
    7.  
    8.  
    9. public float updateInterval = 1.0f;
    10. public Text GUIText;
    11.  
    12. float accum = 0.0f; // FPS accumulated over the interval
    13. int frames = 0; // Frames drawn over the interval
    14. float timeleft; // Left time for current interval
    15. float fps = 30.0f; // Current FPS
    16. double lastSample=0.0;
    17.  
    18.     // Use this for initialization
    19.     void Start ()
    20.     {
    21.         timeleft = updateInterval;
    22.         lastSample = Time.realtimeSinceStartup;
    23.     }
    24.  
    25.  
    26.     void toggle_draw_fps()
    27.     {
    28.         if(GUIText.enabled)
    29.             GUIText.enabled = false;
    30.         else
    31.             GUIText.enabled = true;
    32.     }
    33.  
    34.  
    35.     void Update ()
    36.     {
    37.         frames++;
    38.         double newSample = Time.realtimeSinceStartup;
    39.         float deltaTime = (float)(newSample - lastSample);
    40.         lastSample = newSample;
    41.  
    42.         timeleft -= deltaTime;
    43.         accum += deltaTime;
    44.      
    45.         // Interval ended - update GUI text and start new interval
    46.         if( timeleft <= 0.0f )
    47.         {
    48.          // here we got the frames number and accum for the time they took to draw....
    49.          // lets get the mean time for one frame and show how many of those frame-time we got in 1 sec
    50.          fps = 1.0f/(accum/frames);
    51.      
    52.             // display two fractional digits (f2 format)
    53.             GUIText.text = fps.ToString("f2")+"fps";
    54.             timeleft = updateInterval;
    55.             accum = 0.0f;
    56.             frames = 0;
    57.         }
    58.     }
    59. }
    60.  
    here is a screenshot:
    perf.jpg

    What's wrong with fps ? i can't believe this could be a bug ?????
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The editor FPS statistic is just a curiosity value, nothing more. It is affected by a great number of things. You should use a build for real framerate values. Better still, get used to using millisecs.

    Unity editor is not the place to test this. It's doing a million additional things all the time, and thus has no real value beyond curiosity and doesn't reflect your game's performance.

    Think about it for a moment. Look at it. It's not just your game is it?
     
  3. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    ahahah sure hippocoder unity editor is MY favorite game !!!! :D

    okay i thank you a lot for this answer as i really was surprised for the difference between my measurements
    and stats info. I've been tricked by the former ( long ago was on unity 3.4 ) measurements i made that were
    almost identical to what stats said.

    have a nice day :)
     
    hippocoder likes this.