Author Topic: QB64 Speed?  (Read 3219 times)

0 Members and 1 Guest are viewing this topic.

Offline Kosta

  • Newbie
  • Posts: 9
    • View Profile
QB64 Speed?
« on: August 02, 2019, 06:17:42 pm »
Hi again guys. Please give me hope.  I was really hoping to see my 16 bit QBX code and 32 bit Power Basic code run faster compiled with a 64 bit compiler, but what I'm finding on a simple integer FOR NEXT LOOP that QB64 takes literally 10 times longer to complete the loop than on 32 bit Power Basic console compiler.

Is it that I'm not compiling correctly for 64 bit? I'm just selecting the make EXE only option in the IDE. Please tell me there's a magic 64 bit wand somewhere that I'm not waving correctly?

Kosta

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 Speed?
« Reply #1 on: August 02, 2019, 06:57:06 pm »
No magic wand likely, QB64 runs through middleman C++

but there are ways to make some code go faster... the FOR loop is slowest loop structure for one thing.

Offline Kosta

  • Newbie
  • Posts: 9
    • View Profile
Re: QB64 Speed?
« Reply #2 on: August 02, 2019, 07:21:54 pm »
But if it's compiling as 64 bit in the end, and C++ 64 bit compiled code is really fast, why is the compiled QB64 emitted code 10x slower than 32 bit power basic code? Long integers are fast. Just having QB64 increment an integer takes 30 seconds to do what 3 seconds does in 15 year-old 32 bit power basic.

Something has to be wrong here. A compiled 64bit C++ function is not going to take 10x longer to run than power basic's 32bit compiler. No way no how.  There has to be some settings in the compiler that have default settings of some form or another that are affecting the performance.  I don't code in C++, so I'm not familiar with those compilers, which is why I was looking at QB64 to let me code in basic but get a 64 bit compiled .EXE that should run like it was coded in C++. But this is definitely not even close.  There must be something wrong here!!! I don't want to lose faith! Help!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 Speed?
« Reply #3 on: August 02, 2019, 07:37:36 pm »
Can you share the code you’re testing?  It’ll help in seeing what the issue is.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kosta

  • Newbie
  • Posts: 9
    • View Profile
Re: QB64 Speed?
« Reply #4 on: August 02, 2019, 07:45:03 pm »

DIM I AS LONG
DIM A AS LONG

PRINT TIME$
FOR I = 1 TO 1000000

    FOR A = 1 TO 3000

    NEXT
NEXT
PRINT TIME$
INPUT G$

Offline Kosta

  • Newbie
  • Posts: 9
    • View Profile
Re: QB64 Speed?
« Reply #5 on: August 02, 2019, 07:45:59 pm »
That takes 30 seconds to complete on my laptop with QB64, and 3 seconds with power basic console compiler (32 bit.)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 Speed?
« Reply #6 on: August 02, 2019, 08:04:36 pm »
This runs 6 secs down from 8 secs on FOR LOOP and no checking meta
Code: QB64: [Select]
  1.  
  2.     A = 0
  3.     DO
  4.         A = A + 1
  5.     LOOP UNTIL A = 3000
  6.     I = I + 1
  7. LOOP UNTIL I = 1000000
  8.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 Speed?
« Reply #7 on: August 02, 2019, 08:08:13 pm »
Running on my PC takes about 10 seconds, as is.

If you go into \internal\c\ and open makeline_win.txt, you can set the compiler flags to optimize for speed (just add the -O3 flag to the makeline), recompile, and the time cuts down to about half of that (around 5 seconds).

Change that FOR NEXT structure into a DO...LOOP structure (which translates to a little cleaner c), and the time drops down to about 3 seconds.

Just a few little tricks which you can use to optimize performance a bit better.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 Speed?
« Reply #8 on: August 02, 2019, 08:19:22 pm »
And, if we want to do it the super-quick, fancy way, we can do the process by looking and changing our values directly in memory:

Code: [Select]
DIM I AS LONG: DIM A AS LONG
DIM X AS _MEM: DIM Y AS _MEM
X = _MEM(I): Y = _MEM(A)

t# = TIMER

$CHECKING:OFF
_MEMPUT X, X.OFFSET, 1 AS LONG
DO UNTIL _MEMGET(X, X.OFFSET, LONG) > 1000000
    _MEMPUT Y, Y.OFFSET, 1 AS LONG
    DO UNTIL _MEMGET(Y, Y.OFFSET, LONG) > 3000
        _MEMPUT Y, Y.OFFSET, _MEMGET(Y, Y.OFFSET, LONG) + 1 AS LONG
    LOOP
    _MEMPUT X, X.OFFSET, _MEMGET(X, X.OFFSET, LONG) + 1 AS LONG
LOOP
$CHECKING:ON
PRINT USING "##.### seconds)"; TIMER - t#
INPUT G$

The same routine now runs in about 1.6 seconds on my PC...

A lot of performance depends on just how much you actually *NEED* it.  QB64 can get as fast as anything else out there, but it may not be worth the hassle to have to code things just for the speed boost alone.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: QB64 Speed?
« Reply #9 on: August 02, 2019, 11:01:06 pm »
Do you need LONG? If not, DIM as INTEGER. INTEGER operations run much faster.

BTW: The "$CHECKING:OFF" statement turns error checking off, which makes the code run more like it would in any other language where error checking isn't present in the compiled exe. Only use $CHECKING:OFF if you are sure your code is debugged.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: QB64 Speed?
« Reply #10 on: August 03, 2019, 04:47:14 am »
Steve wrote:

Quote
And, if we want to do it the super-quick, fancy way, we can do the process by looking and changing our values directly in memory:

Steve, which IDE version you use? Your code run 7.9 seconds for me, so as source with DO-LOOP version by BPlus

Pete wrote:

Quote
Do you need LONG? If not, DIM as INTEGER. INTEGER operations run much faster.
Is possible just for A in this source code. Try set I as integer - for neverending loop due to owerflow :-D

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 Speed?
« Reply #11 on: August 03, 2019, 05:43:48 am »
Steve, which IDE version you use? Your code run 7.9 seconds for me, so as source with DO-LOOP version by BPlus

go into \internal\c\ and open makeline_win.txt, you can set the compiler flags to optimize for speed (just add the -O3 flag to the makeline), recompile

OR copy the following and use it to replace the makeline_win.txt file in the internal/c/ folder:

Code: [Select]
c_compiler\bin\g++ -O3 -s -Wfatal-errors -w -Wall qbx.cpp -lws2_32 -lwinspool parts\core\os\win\src.a -lopengl32 -lglu32 -lwinmm -lgdi32 -mwindows -static-libgcc -static-libstdc++ -D GLEW_STATIC -D FREEGLUT_STATIC -lksguid -lole32 -lwinmm -ldxguid -o ..\..\
Add that -O3 flag (or even -Ofast instead), and then compile the code and see what the difference in the speed might be for you. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!