Page 1 of 1

Speed ​​of a program...

Posted: Thu Jun 05, 2025 10:38 pm
by SPH
Hi,

Regarding my game "MAGIC 4x4," I tried it on several computers and noticed that it didn't run at the same speed at all!
Why?
It runs slowly on a 6-year-old laptop; as if it were a PENTIUM 266! :shock:

Did I miss something about the PB language?

Do I need to create a routine to calculate the speed and perform multiplication for all my procedures? (I'm willing to do it.)

Thanks :idea:

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 3:20 am
by tua
Without your complete source code nobody can give a meaningful answer.

I'd like to share two personal observations (without potentially wanting to bruise your ego):

1) PureBasic is very fast - close to the speed of C mostly.

2) More often than not, the cause of slow execution is not the language, but sits at the keyboard....

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 4:23 am
by Demivec
SPH wrote: Thu Jun 05, 2025 10:38 pm Do I need to create a routine to calculate the speed and perform multiplication for all my procedures? (I'm willing to do it.)
Yes. :)

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 4:30 am
by AZJIO
Add this code to your templates

Code: Select all

StartTime = ElapsedMilliseconds()
Delay(1000) ; test code
Debug "Delay() = " + Str(ElapsedMilliseconds() - StartTime) + " ms"
You can create a test version that writes a log file.

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 6:34 am
by Fred
Some commands are known to be very slow by nature, like ScreenOutput() and it can't be avoided. If you use sprite only command it should be very fast.

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 9:05 am
by Caronte3D
I don't like the use of GoTo and GoSub (or more than one FlipBuffers()) but... apart of it, maybe you need to implement the concept of deltatime (widely used in game-engines) to keep the same speed independently of the machine speed.
Little example:

Code: Select all

InitSprite()
InitKeyboard()

OpenScreen(800, 600, 32, "Delta Time Example")

Define.f deltaTime
Define lastTime = ElapsedMilliseconds()
Define.f posX = 100
Define.f speed = 200.0 ; pixeles per second

Repeat
  ; Calculate deltaTime -------------------------------------
  currentTime = ElapsedMilliseconds()
  deltaTime = (currentTime - lastTime) / 1000.0 ; en segundos
  lastTime = currentTime
  ; ---------------------------------------------------------

  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Right)
    posX + speed * deltaTime
  EndIf
  If KeyboardPushed(#PB_Key_Left)
    posX - speed * deltaTime
  EndIf

  StartDrawing(ScreenOutput())
  DrawText(10, 10, "posX: " + StrF(posX))
  DrawText(10, 30, "deltaTime: " + StrF(deltaTime, 4))
  Box(posX, 100, 50, 50, RGB(255, 0, 0))
  StopDrawing()
  
  FlipBuffers()
  ClearScreen(RGB(0, 0, 0))

Until KeyboardPushed(#PB_Key_Escape)

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 9:14 am
by Fred
You can also use SetFrameRate() so you know at which speed it will work.

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 5:09 pm
by SPH
Does a grabsprite also consume "speed"?

Re: Speed ​​of a program...

Posted: Fri Jun 06, 2025 9:43 pm
by Fred
Yes, it's like ScreenOutput() as you need to read the backbuffer which is very slow and then create a new sprite.

Re: Speed ​​of a program...

Posted: Sat Jun 07, 2025 2:13 pm
by SPH
Fred wrote: Fri Jun 06, 2025 9:43 pm Yes, it's like ScreenOutput() as you need to read the backbuffer which is very slow and then create a new sprite.
Is it the Screen Output() call itself that's slow?
Or is it the size of the copied data?
(I assume both, but I'd like "%" proportions.)

Re: Speed ​​of a program...

Posted: Sat Jun 07, 2025 4:10 pm
by Fred
It's ScreenOutput()

Re: Speed ​​of a program...

Posted: Sat Jun 07, 2025 8:54 pm
by SPH
Ok, thx :idea:

Re: Speed ​​of a program...

Posted: Sat Jun 07, 2025 9:42 pm
by SMaag
The Speed difference is not an issue of PB. It depends on GPU or CPU drawing.
Especally at lo cost Notebook processors some GPU functions are missing. In that cases DirectX use CPU functions instead of GPU functions.

Re: Speed ​​of a program...

Posted: Sun Jun 08, 2025 5:08 pm
by Piero
I think I'm missing something…
Are you saying there isn't a (posted on this forum) general way to say: "your game is running slowly; this is cheating!" (or to slow down stuff on a very powerful machine)?
;P