Page 1 of 1

Is this weird or am I tired?

Posted: Thu Nov 24, 2005 4:04 am
by Joakim Christiansen
Without any delay this code gives me 1100 FPS.
With a delay of just 1ms this gives me only 64 FPS.
Is this weird or am I just tired? :lol:

Code: Select all

InitKeyboard(): InitSprite()
OpenScreen(640,480,16,"FPS Test")

Procedure.l GetFPS()
  Static Time, Frames, FPS
  
  Frames + 1
  
  If ElapsedMilliseconds()-Time >= 1000
    Time = ElapsedMilliseconds()
    FPS = Frames
    Frames = 0
  EndIf
  
  ProcedureReturn FPS
EndProcedure

Repeat
  FlipBuffers(0)
  ClearScreen(255,255,255)
  
  StartDrawing(ScreenOutput())
    Locate(10,10)
    DrawText(Str(GetFPS()))
  StopDrawing()
  
  ExamineKeyboard()
  Delay(1)
Until KeyboardPushed(#PB_Key_Escape)

Posted: Thu Nov 24, 2005 9:34 am
by Chris
2300 and more :lol:

Refresh rate for my screen : 85 Hz

Posted: Thu Nov 24, 2005 10:19 am
by dmoc
By using Delay() you are effectively suspending your program and freeing the CPU for other tasks (check cpu usage, prob goes from 100 to 0). Task switching on Windows can take around 10..20ms hence once you use it you get a much lower figure. The numbers you are quoting confuse program "loop" rate with screen refresh rate. FPS itself can be confusing depending on what you are doing (eg, updating physics/ game ai/ actual display redraw). Loop time includes display refresh time AND any inherent delay waiting to refresh the display (on calling FlipBuffers()). It gets even more confusing when you introduce double/triple buffering, but much simpler (poss) if you have activated vsync'ing. Any delay on calling FlipBuffers() represents time unavailable to your other code unless you push the FlipBuffers() to as near to a vsync as poss. The holy grail seems to be "phase locking" the refresh of the display with vsync but with no vsync'ing set in driver. I've had limited success doing this specifically because of Delay().

Posted: Thu Nov 24, 2005 10:55 am
by Psychophanta
Joakim, i don't see what is weird there!!!
Chris, refresh rate of screen has nothing to do for that code
:)

Posted: Thu Nov 24, 2005 1:36 pm
by GeoTrail
64 FPS with the delay and 2431 FPS without the delay. Don't seem weird to me, like Psychophanta said :)
Got it upto 4495 FPS without ClearScreen(255,255,255) hehe.

Posted: Thu Nov 24, 2005 1:44 pm
by Chris
Psychophanta wrote:Joakim, i don't see what is weird there!!!
Chris, refresh rate of screen has nothing to do for that code
:)
If i disable Delay(1) and if i use FlipBuffer(1), the FPS is 60 and with FlipBuffer(0), the FPS is 2800/3200.

PS i have set my refresh rate to 60 Hz for the test.