Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why to use native code compilation?

Posted on 1998-12-17
15
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Suggested Courses

609 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