Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Getting strange Frames Per Second results (Pics included)  (Read 3057 times)

0 Members and 1 Guest are viewing this topic.

Pindrought

  • Newbie
  • *
  • Posts: 11
    • View Profile
Getting strange Frames Per Second results (Pics included)
« on: April 03, 2016, 10:33:37 pm »
So, when I insert a Sleep(1) command in my loop that is polling/rendering for my window, I get about 100 fps as shown in this image.




However, when I remove the sleep command, I get about 8,300 FPS as shown in this image.



I am trying to understand why putting Sleep(1) takes my fps from 8300 down to 100. I would think that it would take it down to a bit under 1000 if it is normally 8,300 since there are 1,000 miliseconds in one second and Sleep(1) is only sleeping for 1 milisecond.

This is not a serious problem, but I am just curious as to why this happens if anybody knows. I included the Sleep there because I didn't want to put too much strain on the CPU. I didn't think it would reduce the fps by that much though.



Edit (4:56PM) - Well I just tried it again, and now i'm getting around 1000 fps with Sleep(1). It's just strange because after a few tries my fps will go back down to 100 for a few executions and then it will go back to 1000.

« Last Edit: April 03, 2016, 10:57:04 pm by Pindrought »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Getting strange Frames Per Second results (Pics included)
« Reply #1 on: April 04, 2016, 12:22:50 am »
If you want more accuracy in your sleeping duration, you can:
  • Quote
    call the timeGetDevCaps function to determine the supported minimum timer resolution and the timeBeginPeriod function to set the timer resolution to its minimum
    - Windows' Sleep function,
  • use sf::Sleep as it attempts to use the highest resolution available,
  • loop until a specific amount of time has lapsed.
That final suggestion would be the most accurate but would not but technically sleeping, rather it would be waiting (and somewhat hogging the CPU).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Getting strange Frames Per Second results (Pics included)
« Reply #2 on: April 05, 2016, 02:10:16 am »
Since it may not have been clear from Hapax's post, the key point here is that most sleep() functions are not guaranteed to sleep for exactly the length of time you ask them to. Many of them will effectively act as if they're rounding the time you give them up or down to a multiple of whatever timer resolution the OS supports.

Pindrought

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Getting strange Frames Per Second results (Pics included)
« Reply #3 on: April 05, 2016, 02:41:26 am »
Thank you very much both of you for your replies! It makes more sense now.

 

anything