Is this weird or am I tired?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Is this weird or am I tired?

Post 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)
I like logic, hence I dislike humans but love computers.
Chris
User
User
Posts: 60
Joined: Wed Jun 11, 2003 4:54 pm
Location: Somewhere... But i can see you!

Post by Chris »

2300 and more :lol:

Refresh rate for my screen : 85 Hz
My english is bad !!!... It's normal, i'm french :lol:
My english is not really the English.
It's the FrogLish (Froggy's English) ;)
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post 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().
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Joakim, i don't see what is weird there!!!
Chris, refresh rate of screen has nothing to do for that code
:)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post 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.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Chris
User
User
Posts: 60
Joined: Wed Jun 11, 2003 4:54 pm
Location: Somewhere... But i can see you!

Post 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.
My english is bad !!!... It's normal, i'm french :lol:
My english is not really the English.
It's the FrogLish (Froggy's English) ;)
Post Reply