How to assess frames per second?
BlitzMax Forums/BlitzMax Programming/How to assess frames per second?
| ||
I wonder if someone(s) can confirm whether this following program is correct to assess the frames-per-second framerate of a given loop (heavily commented for your delectation)..... I used to go by knowing what the refresh rate of the display is (e.g. 50Hz and doing the math in comparison to that benchmark, but this needs to be htz independent). Millisecs() is 1000ths of a second right? 'Is this a correct program to read the frames per second? ..........: Local counter:Int=MilliSecs() 'Store current MilliSecs() reading Local passage:Int=0 'Initialize passage of time since last frame Local m:Int=0 'Initialize temporary variable for math Local fps:Int=0 'Initialize frames per sercond result variable Repeat 'keep going ' 'do Max2D graphics processing stuff here ' m=MilliSecs() ' Get the current MilliSecs() so that the number is consistent passage=m-counter 'Passage of time since the last iteration of the loop fps=1000/passage 'Fps is 1000 (millisecs) / millisecs since last loop? counter=m ' Store current reading for next time SetRotation 0 'Undo rotation settings from earlier in the graphics stuff SetScale 1,1 'Undo scale from earlier too DrawText fps+"fps",0,0 'So that this text draws right - the framerate Flip ' Flip the backbuffer into view Until KeyHit(KEY_ESCAPE) 'keep going until escape key hit |
| ||
Looks about right. What gets me tho is the int being used for millisecs. shouldn't that be a long? |
| ||
I thought Int's were 32bit, same thing? otherwise it would be a double? |
| ||
woops. wrong basic. i was assuming int (as in C and powerbasic) is 16bit. but you're right, it's 32bit. |
| ||
I have always found this more stable and exact. I pasted yours into the fireworks demo and it changes way to much (unreadable for me).'FPS_Counter <> Runs And displays the FPS '-------------------------------------------- SetRotation 0 'Undo rotation SetScale 1,1 'Undo scale FPS_Counter=FPS_Counter+1 If FPS_Counter_time+1000 =< MilliSecs() FPS=FPS_Counter' <- Frames/Sec FPS_Counter=0 FPS_Counter_time=MilliSecs() EndIf DrawText "Current FPS: "+FPS,20,20 '--------------------------------------------This is porbably not optimal, but it gives a accurate FPS for tweaking |