Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

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 !!!!
0
anmella
Asked:
anmella
  • 3
1 Solution
 
anmellaAuthor Commented:
Adjusted points to 75
0
 
p_biggelaarCommented:
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.

0
 
caraf_gCommented:
"when I compile and generate a DOS executable with firstbasic (a Qbasic compiler) I obtain a very quick code."

Q1 - Does firstbasic generate a 32-bit executable?

Q2 - Do you need to do anything else in this executable

If the answer to Q1 is Yes and the answer to Q2 is No, I'd say, forget about translating it to VB and use firstbasic in this particular case.

VB runs through a run-time DLL. You'll always have a performance hit compared to something compiled into a small self-contained .exe


0
 
anmellaAuthor Commented:
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.
0
 
anmellaAuthor Commented:
Thanks again.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now