Speed on PB is slow ?!

Everything else that doesn't fall into one of the other PB categories.
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Speed on PB is slow ?!

Post by threedslider »

Hi

I make a simple for the loop to 1 000 000 000 and it is quite slow :shock:

See it by yourself :lol:

Here the code :

Code: Select all

Procedure.i Adder(i.i)
  ProcedureReturn i + 1
  
EndProcedure

i.i = 0
TimeStart = ElapsedMilliseconds() 
While i < 1000000000
  adder(i)
  
  i = i+1
Wend

Debug Str((ElapsedMilliseconds() - TimeStart)) + " milliseconds"
And time is here :

Code: Select all

147684 milliseconds
User avatar
mk-soft
Always Here
Always Here
Posts: 6224
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Speed on PB is slow ?!

Post by mk-soft »

With Debugger

Code: Select all

Start ...
Done 48950 milliseconds
Without Debugger

Code: Select all

Start ...
Done 1881 milliseconds
Not Slow ;)

Code: Select all

Procedure.i Adder(i.i)
  ProcedureReturn i + 1
  
EndProcedure

If OpenConsole()
  i.i = 0
  PrintN("Start ...")
  TimeStart = ElapsedMilliseconds() 
  While i < 1000000000
    adder(i)
    
    i = i+1
  Wend
  PrintN("Done " +Str((ElapsedMilliseconds() - TimeStart)) + " milliseconds")
  Input()
EndIf

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
TI-994A
Addict
Addict
Posts: 2725
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Speed on PB is slow ?!

Post by TI-994A »

threedslider wrote: Tue Aug 12, 2025 4:01 pmI make a simple for the loop to 1 000 000 000 and it is quite slow :shock:
Such results are highly contingent on the hardware its running on.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

Re: Speed on PB is slow ?!

Post by le_magn »

mk-soft wrote: Tue Aug 12, 2025 4:15 pm With Debugger

Code: Select all

Start ...
Done 48950 milliseconds
Without Debugger

Code: Select all

Start ...
Done 1881 milliseconds
Hi MK-SOFT, I’d like to ask which CPU you have. Without a debugger, I get 1400ms, but with a debugger, it takes twice your time, 85000ms, PB 6.21 32/64

UPDATE: I repeated the test with C Backend and now this is the result:

Code: Select all

With debugger:
22552ms

Code: Select all

without debugger:
0ms
CPU: AMD Ryzen 9950X3D
Last edited by le_magn on Wed Aug 13, 2025 12:01 am, edited 2 times in total.
Image
User avatar
NicTheQuick
Addict
Addict
Posts: 1510
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Speed on PB is slow ?!

Post by NicTheQuick »

On my machine the code is done in 0 milliseconds. I guess the optimization is working fine. :D

Without optimization it is 1512 milliseconds. :wink:

So don't forget to enable optimizations in the compiler options.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Speed on PB is slow ?!

Post by threedslider »

@mk-soft : Oh ok I see that xD, yes my without debugger is pretty fast :)

@TI-994A : true

@NicTheQuick : How you did that ??? Say me your tips please !!
User avatar
NicTheQuick
Addict
Addict
Posts: 1510
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Speed on PB is slow ?!

Post by NicTheQuick »

threedslider wrote: Tue Aug 12, 2025 7:21 pm@NicTheQuick : How you did that ??? Say me your tips please !!
You have to enable the compiler optimizations in the compiler options. And of course for that you have to use the C backend and not the ASM backend. The ASM backend has no future anyway in my opinion.
Last edited by NicTheQuick on Wed Aug 13, 2025 10:25 am, edited 1 time in total.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
AZJIO
Addict
Addict
Posts: 2152
Joined: Sun May 14, 2017 1:48 am

Re: Speed on PB is slow ?!

Post by AZJIO »

Windows 11 x64, PB 6.21 x64, AMD Ryzen 5 8500G OEM
92614 - ASM, with Debugger
1203 - ASM, without Debugger
32547 - C-Backend, with Debugger, without optimization
26440 - C-Backend, with Debugger, with optimization
1591 - C-Backend, without Debugger, without optimization
201 - C-Backend, without Debugger, with optimization
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 459
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Speed on PB is slow ?!

Post by Mindphazer »

On my Mac M4 :
Debugger on : 21749 ms
Debuger off without optimization : 1578 ms
Debugger off with optimization : 0 ms

On Mac Mx series, only C Backend is available

PB is slow, really ?
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
BarryG
Addict
Addict
Posts: 4155
Joined: Thu Apr 18, 2019 8:17 am

Re: Speed on PB is slow ?!

Post by BarryG »

3167 ms on my very old PC. This is running it as a compiled exe, built with the ASM backend with v6.10 of PureBasic.
User avatar
idle
Always Here
Always Here
Posts: 5855
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Speed on PB is slow ?!

Post by idle »

NicTheQuick wrote: Tue Aug 12, 2025 5:57 pm On my machine the code is done in 0 milliseconds. I guess the optimization is working fine. :D

Without optimization it is 1512 milliseconds. :wink:

So don't forget to enable optimizations in the compiler options.
C Optimizer removed the loop. :lol:
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Speed on PB is slow ?!

Post by threedslider »

@idle : Yeah it is possible :lol:
threedslider
Enthusiast
Enthusiast
Posts: 393
Joined: Sat Feb 12, 2022 7:15 pm

Re: Speed on PB is slow ?!

Post by threedslider »

Mindphazer wrote: Tue Aug 12, 2025 10:26 pm PB is slow, really ?
I know now but only debugger is slow a bit ... Yeah otherwise PB is very fast :shock:
User avatar
NicTheQuick
Addict
Addict
Posts: 1510
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Speed on PB is slow ?!

Post by NicTheQuick »

idle wrote: Wed Aug 13, 2025 2:48 am
NicTheQuick wrote: Tue Aug 12, 2025 5:57 pm On my machine the code is done in 0 milliseconds. I guess the optimization is working fine. :D

Without optimization it is 1512 milliseconds. :wink:

So don't forget to enable optimizations in the compiler options.
C Optimizer removed the loop. :lol:
Exactly :lol:
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Lord
Addict
Addict
Posts: 901
Joined: Tue May 26, 2009 2:11 pm

Re: Speed on PB is slow ?!

Post by Lord »

Interesting:

If I use For/Next, the execution time ist just 50% with Debugger on.
C-Backend is selected and Optimization is enabled.
31106 ms to 69440 ms
Without Debugger: both 0 ms

Win11 x64, PB6.20 x64, i5-13400F
Image
Post Reply