Just starting out? Need help? Post your questions and find answers here.
SPH
Enthusiast
Posts: 565 Joined: Tue Jan 04, 2011 6:21 pm
Post
by SPH » Thu Jun 05, 2025 10:38 pm
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!
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
!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
Posts: 68 Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada
Post
by tua » Fri Jun 06, 2025 3:20 am
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....
Demivec
Addict
Posts: 4265 Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA
Post
by Demivec » Fri Jun 06, 2025 4:23 am
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
Posts: 2156 Joined: Sun May 14, 2017 1:48 am
Post
by AZJIO » Fri Jun 06, 2025 4:30 am
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
Posts: 18167 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » Fri Jun 06, 2025 6:34 am
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.
Caronte3D
Addict
Posts: 1361 Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe
Post
by Caronte3D » Fri Jun 06, 2025 9:05 am
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
Posts: 18167 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » Fri Jun 06, 2025 9:14 am
You can also use SetFrameRate() so you know at which speed it will work.
SPH
Enthusiast
Posts: 565 Joined: Tue Jan 04, 2011 6:21 pm
Post
by SPH » Fri Jun 06, 2025 5:09 pm
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
Posts: 18167 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » 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.
SPH
Enthusiast
Posts: 565 Joined: Tue Jan 04, 2011 6:21 pm
Post
by SPH » Sat Jun 07, 2025 2:13 pm
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
Posts: 18167 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » Sat Jun 07, 2025 4:10 pm
It's ScreenOutput()
SPH
Enthusiast
Posts: 565 Joined: Tue Jan 04, 2011 6:21 pm
Post
by SPH » Sat Jun 07, 2025 8:54 pm
Ok, thx
!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
Posts: 317 Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany
Post
by SMaag » Sat Jun 07, 2025 9:42 pm
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.
Piero
Addict
Posts: 886 Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy
Post
by Piero » Sun Jun 08, 2025 5:08 pm
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