Solved

Why to use native code compilation?

Posted on 1998-12-17
15
320 Views
Last Modified: 2010-05-03
I'm developing VB5 app's.
Don't interest me the debugging features.
When I compile to native code, the EXE is of 1,2 MB. When I compile to pcode the EXE it is of 720 KB. I don't notice differences in the performance.
Why to use native code compilation?
Are the optimization switchs useful in the real life?

Thank you for their help
0
Comment
Question by:CarlosJac
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1451136
If you are doing any mathematics, you will see great difference.
If you are using arrays, removing bounds check will make your app fly.
If you switch on "Assume no aliasing", your loops will be faster.

Of course, wrong usage can couse GPF.
0
 
LVL 1

Author Comment

by:CarlosJac
ID: 1451137
ameba:

Thank you for your answer. I reject your answer to give place to the opinion of other experts.
Keeping in mind what you say, the optimization switches don't seem to be very useful .

If I switch on "Assume no aliasing", my loops will be faster, but my app use ByRef ...

If I remove bounds check will make my app fly, but I can 've problems with my existent code ...
What cautions should I take to avoid the problems that I can suffer having this switch on?

I hope you understand me. My English is very poor.

Thanks

Carlos

0
 
LVL 2

Expert Comment

by:spenner
ID: 1451138
As a general rule, I don't use any optimizations as I have found that they tend to cause crashes - especially when the compiled programs are used on NT systems.  However, one "optimization" I will never use is compiling to Pcode, because it's simply a method of maintaining compatibility for vb 3 as vb3 compiled its programs to pcode.
0
 
LVL 1

Author Comment

by:CarlosJac
ID: 1451139
spenner:

Thank you for your answer, but Why to use native code compilation if I don't notice differences in the performance, and the code size is doubled?

 
 

0
 
LVL 15

Expert Comment

by:ameba
ID: 1451140
>"Assume no aliasing", my loops will be faster, but my app use ByRef ...
This option has nothing to do with using ByRef.
It allows using processor registers.
-------
I don't wan't you to have troubles, so better you don't use optimization or don't blame me, when you will have troubles.

To use it:
1. You must be experienced, prepared for problems, or have a lot of E-E points :)
2. You must have a need for optimization:
E.g. you see an utility to do something (e.g. process a file).
You create the same thing, but much, much nicer and better user interface.
The util costs $10, so your should be say $15.
Then you try processing 1MB file and find it needs 20 seconds (the ugly one needs 1 second).
This is the situation for optimization.
0
 
LVL 1

Author Comment

by:CarlosJac
ID: 1451141
ameba: Again, thank you

Looks at what the vb books online says about asume no aliasing:

Using this option allows the compiler to apply optimizations it couldn't otherwise use, such as storing variables in registers and performing loop optimizations. However, you should be careful not to check this option if your program passes arguments ByRef, since the optimizations could cause the program to execute incorrectly.


ameba:

I am very grateful for your help. I don't have anything to blame you

0
 
LVL 15

Expert Comment

by:ameba
ID: 1451142
CarlosJac,
I would like you to see the difference in speed.
Start new project, add command button, paste this code to your form:
Option Explicit
Private myArray() As Double
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()
    Dim i As Long, j As Long, numtests As Integer, tim0 As Long
    Dim max As Long
    max = UBound(myArray)
    numtests = 10
    tim0 = GetTickCount ' start timing
    ' our loop
    For j = 1 To numtests
        For i = 1 To max
            myArray(i) = myArray(i) + 0.5
        Next
    Next
    ' report time
    Caption = (GetTickCount - tim0) / 1000
End Sub

Private Sub Form_Load()
    ReDim myArray(1 To 500000)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Erase myArray ' free memory
End Sub

0
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.

 
LVL 15

Expert Comment

by:ameba
ID: 1451143
Please, make 2 exe:
1. P-code (Project1.Exe)
2. Fast optimization, with first 4 adv. options On (Project2.Exe)

Tell me what you measured.
0
 
LVL 15

Expert Comment

by:ameba
ID: 1451144
ameba wrote about 'asume no aliasing'
>>>but my app use ByRef
>>This option has nothing to do with using ByRef

Hey, read carefully. It doesn't say:
"This occurs when using ByRef arguments."
It says:
"This occurs when using ByRef arguments that refer to the same ..."

0
 
LVL 1

Author Comment

by:CarlosJac
ID: 1451145
ameba:

Put your comment as a answer.  The points are yours.
Thank you
0
 
LVL 15

Expert Comment

by:ameba
ID: 1451146
Tell me what you measured
0
 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 1451147
Thanks for your pts.
I measured 9 sec. for p-code, 1.5 sec for full optimization. P120/64MB
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1451148
Carlos: las diferencias de tamaño dependen del modo de compilacion, porque se puede generar un .EXE con TODO lo que necesita en su interior, y, por otro lado, se puede generar un .EXE que solo contiene referencias a rutinas contenidas en archivos .DLL que se suponen ya existentes en la maquina donde se va a ejecutar. Debido a eso, el primero es mucho mayor que el segundo.

==============================================================

Carlos: size differences depend on the way you compile, 'cause you can generate a .EXE, with ALL it needs into it, and, on the other hand, you can create a .EXE which only has references to routines stored at .DLL files, which it's suposed they already exist at the machine where app. will be executed. Due to that, the former is much bigger than the last one.
0
 
LVL 1

Author Comment

by:CarlosJac
ID: 1451149
ameba:
Here's my measures (Pentium 200, 64 MB RAM).

Pcode compilation: 6.649
Native: 1.96
Native with switch 1:      1.913
Native with switch 2:      1.425
Native with switchs 1,2:     1.371
Native with switchs 1,2,6:    0.941
Native with switchs 1,2,3,4:   1.097

vikiing:

Creo que hay un error en lo que dices.  Te estás refiriendo a linking estático vs linking dinámico.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1451150
No, Carlos; no estoy hablando de eso. Pero bueno, eso fue solo un comentario; olvidalo nomas...

0

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

911 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