Speed ​​of a program...

Just starting out? Need help? Post your questions and find answers here.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Speed ​​of a program...

Post 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:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
tua
User
User
Posts: 68
Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada

Re: Speed ​​of a program...

Post 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....
User avatar
Demivec
Addict
Addict
Posts: 4265
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Speed ​​of a program...

Post 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. :)
AZJIO
Addict
Addict
Posts: 2156
Joined: Sun May 14, 2017 1:48 am

Re: Speed ​​of a program...

Post 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.
Fred
Administrator
Administrator
Posts: 18167
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Speed ​​of a program...

Post 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.
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Speed ​​of a program...

Post 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)
Fred
Administrator
Administrator
Posts: 18167
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Speed ​​of a program...

Post by Fred »

You can also use SetFrameRate() so you know at which speed it will work.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Speed ​​of a program...

Post by SPH »

Does a grabsprite also consume "speed"?

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Fred
Administrator
Administrator
Posts: 18167
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Speed ​​of a program...

Post by Fred »

Yes, it's like ScreenOutput() as you need to read the backbuffer which is very slow and then create a new sprite.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Speed ​​of a program...

Post 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.)

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Fred
Administrator
Administrator
Posts: 18167
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Speed ​​of a program...

Post by Fred »

It's ScreenOutput()
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Speed ​​of a program...

Post by SPH »

Ok, thx :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
SMaag
Enthusiast
Enthusiast
Posts: 317
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: Speed ​​of a program...

Post 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.
User avatar
Piero
Addict
Addict
Posts: 886
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Speed ​​of a program...

Post 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
Post Reply