Solved

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

Posted on 2000-02-22
5
231 Views
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 !!!!
0
Comment
Question by:anmella
  • 3
5 Comments
 

Author Comment

by:anmella
ID: 2545972
Adjusted points to 75
0
 
LVL 2

Expert Comment

by:p_biggelaar
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.

0
 
LVL 10

Accepted Solution

by:
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


0
 

Author Comment

by:anmella
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.
0
 

Author Comment

by:anmella
ID: 2549854
Thanks again.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading the Contents of a Directory In Access VBA 5 76
MS Access Search and Replace Using VBA 6 80
vb6 connector to SQL Server 2 37
Help me. 3 60
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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