anmella
asked on
How can approach VB6 code performance to that of a firstbasic exe obtained?
I have a need to perform some calculations over a plain text ascii file.
The VB functions I use are very simple (a loop of calls to mid$ functions for each line of the file) , they should not increase performance time excesivelly.
A piece of sample code follows (not needed to follow it, is an example
of the simple operations used)
1200 OPEN nf_e$ for input as #1
1210 IF EOF(1) THEN CLOSE #1: GOTO 1380
1220 ct0_ow = 0: ct0_to = 0: ct0_no = 0: ct0_aj = 0: ct0 = 0
1230 LINE INPUT #1, RG$
1240 IF MID$(RG$, 22, 1) = "*" THEN GOTO 1210
1250 FOR k = pt1 TO ptu STEP pts
1260 IF ccew$ <> MID$(RG$, k, ctcod) THEN GOTO 1320
1270 npo = k + poso: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_ow = ct0_ow + ct0
1280 npo = k + post: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_to = ct0_to + ct0
1290 npo = k + posn: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_no = ct0_no + ct0
1300 npo = k + posa: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_aj = ct0_aj + ct0
1320 NEXT k
1330 IF caow <> ct0_ow THEN GOTO 1210
1340 IF cato <> ct0_to THEN GOTO 1210
1350 IF cano <> ct0_no THEN GOTO 1210
1360 IF caaj <> ct0_aj THEN GOTO 1210
1370 total = total + 1: GOTO 1210
....
I import the code from a Qbasic file, and with little changes it works fine with
visual basic 6.
The problem is: when I compile and generate a DOS executable with firstbasic (a Qbasic compiler) I obtain a very quick code.
I've tried to generate the same code (with all optimizations activated) to obtain a windows-VB6 executable code, and the code I obtain is -comparatively- frustrating.
It's true that the VB6 code is quicker than qbasic (interpreted),
but firstbasic code (DOS executable) is much quicker than VB6!!!
The follow timetable explains it:
For 1500 lines processed:
Qbasic code (interpreted) VB6 executable firstbasic code (compiled)
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
50 seconds 16 seconds 3 seconds !!!!
I must be able to process hundreds of lines, in an interactive process, and
I'd not like to blow up my brain changing the original qbasic code to perform
akwards optimizations, since all operations are very simple (manipulation of strings and acumulation of results; little things may be optimized here)
Why is so much difference in the performance time????
How could I improve -an an easy manner- the VB code performance ????
Any sugestion would be most appreciated
Thanks a lot !!!!
The VB functions I use are very simple (a loop of calls to mid$ functions for each line of the file) , they should not increase performance time excesivelly.
A piece of sample code follows (not needed to follow it, is an example
of the simple operations used)
1200 OPEN nf_e$ for input as #1
1210 IF EOF(1) THEN CLOSE #1: GOTO 1380
1220 ct0_ow = 0: ct0_to = 0: ct0_no = 0: ct0_aj = 0: ct0 = 0
1230 LINE INPUT #1, RG$
1240 IF MID$(RG$, 22, 1) = "*" THEN GOTO 1210
1250 FOR k = pt1 TO ptu STEP pts
1260 IF ccew$ <> MID$(RG$, k, ctcod) THEN GOTO 1320
1270 npo = k + poso: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_ow = ct0_ow + ct0
1280 npo = k + post: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_to = ct0_to + ct0
1290 npo = k + posn: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_no = ct0_no + ct0
1300 npo = k + posa: ct0 = VAL(MID$(RG$, npo, lcam)): ct0_aj = ct0_aj + ct0
1320 NEXT k
1330 IF caow <> ct0_ow THEN GOTO 1210
1340 IF cato <> ct0_to THEN GOTO 1210
1350 IF cano <> ct0_no THEN GOTO 1210
1360 IF caaj <> ct0_aj THEN GOTO 1210
1370 total = total + 1: GOTO 1210
....
I import the code from a Qbasic file, and with little changes it works fine with
visual basic 6.
The problem is: when I compile and generate a DOS executable with firstbasic (a Qbasic compiler) I obtain a very quick code.
I've tried to generate the same code (with all optimizations activated) to obtain a windows-VB6 executable code, and the code I obtain is -comparatively- frustrating.
It's true that the VB6 code is quicker than qbasic (interpreted),
but firstbasic code (DOS executable) is much quicker than VB6!!!
The follow timetable explains it:
For 1500 lines processed:
Qbasic code (interpreted) VB6 executable firstbasic code (compiled)
--------------------------
50 seconds 16 seconds 3 seconds !!!!
I must be able to process hundreds of lines, in an interactive process, and
I'd not like to blow up my brain changing the original qbasic code to perform
akwards optimizations, since all operations are very simple (manipulation of strings and acumulation of results; little things may be optimized here)
Why is so much difference in the performance time????
How could I improve -an an easy manner- the VB code performance ????
Any sugestion would be most appreciated
Thanks a lot !!!!
Well. There is no single way of doing it right. Some things you can do:
- if no user interaction is required, get rid of all the forms, and put all your code in a module. Make sure that the module at least has a sub called 'main', so that will be used to start your program.
- before you compile the program, first check the project properties from the project menu. Click on the Compile tab and play with the different optimization options.
- if no user interaction is required, get rid of all the forms, and put all your code in a module. Make sure that the module at least has a sub called 'main', so that will be used to start your program.
- before you compile the program, first check the project properties from the project menu. Click on the Compile tab and play with the different optimization options.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well . It looks like I'll have to adapt
the whole thing the following way:
1- A permanent dos-exe program running, wich does all the processing.
It waits until a signal arises (a parameters file is created), and then it reads the parameters file, and does the processing related to those parameters, writing the results into a results file, and deleting the parameters file.
2- The vb6 program, when has the need to do the calculation, creates a parameters file, and waits until a results file is created, to read the results and display them.
It works fine for me, since the time to create and read a file are insignificant compared to those of processing.
Since, as says carafq, "VB runs through a run-time DLL. You'll always have a performance hit compared to something compiled into a small self-contained .exe " and the dos-code generated in firstbasic compiler is a 32-bit executable, it looks like the folks of Microsoft could have done things better!!!
Anyway, thanks to both of you, Mr.caraf q and p biggelaar, this time the points go to caraf q, sorry since I don't know how to share the points between both of you, but the carafq response is more accurate.
Thanks again to both of you.
the whole thing the following way:
1- A permanent dos-exe program running, wich does all the processing.
It waits until a signal arises (a parameters file is created), and then it reads the parameters file, and does the processing related to those parameters, writing the results into a results file, and deleting the parameters file.
2- The vb6 program, when has the need to do the calculation, creates a parameters file, and waits until a results file is created, to read the results and display them.
It works fine for me, since the time to create and read a file are insignificant compared to those of processing.
Since, as says carafq, "VB runs through a run-time DLL. You'll always have a performance hit compared to something compiled into a small self-contained .exe " and the dos-code generated in firstbasic compiler is a 32-bit executable, it looks like the folks of Microsoft could have done things better!!!
Anyway, thanks to both of you, Mr.caraf q and p biggelaar, this time the points go to caraf q, sorry since I don't know how to share the points between both of you, but the carafq response is more accurate.
Thanks again to both of you.
ASKER
Thanks again.
ASKER