QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: Kosta 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
-
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.
-
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!
-
Can you share the code you’re testing? It’ll help in seeing what the issue is.
-
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$
-
That takes 30 seconds to complete on my laptop with QB64, and 3 seconds with power basic console compiler (32 bit.)
-
This runs 6 secs down from 8 secs on FOR LOOP and no checking meta
A = 0
A = A + 1
I = I + 1
-
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. :)
-
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:
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.
-
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
-
Steve wrote:
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:
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
-
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:
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.