How can approach VB6 code performance to that of a firstbasic exe obtained?

Posted on 2000-02-22
Last Modified: 2010-05-02
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 !!!!
Question by:anmella
  • 3

Author Comment

ID: 2545972
Adjusted points to 75

Expert Comment

ID: 2546459
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.

LVL 10

Accepted Solution

caraf_g earned 70 total points
ID: 2546788
"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


Author Comment

ID: 2549851
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.

Author Comment

ID: 2549854
Thanks again.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now