SFML community forums

Help => Graphics => Topic started by: Pindrought on April 03, 2016, 10:33:37 pm

Title: Getting strange Frames Per Second results (Pics included)
Post by: Pindrought 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.

(http://i.imgur.com/mAe3kPY.png)


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

(http://i.imgur.com/7ngLQEZ.png)

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.

(http://i.imgur.com/Y9GW3dX.png)
Title: Re: Getting strange Frames Per Second results (Pics included)
Post by: Hapax on April 04, 2016, 12:22:50 am
If you want more accuracy in your sleeping duration, you can:
That final suggestion would be the most accurate but would not but technically sleeping, rather it would be waiting (and somewhat hogging the CPU).
Title: Re: Getting strange Frames Per Second results (Pics included)
Post by: Ixrec 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.
Title: Re: Getting strange Frames Per Second results (Pics included)
Post by: Pindrought on April 05, 2016, 02:41:26 am
Thank you very much both of you for your replies! It makes more sense now.