fromVB wrote:So it is translated to assembly that is not optimized? I'm confused.
This is correct. Check this out, for example:
Code: Select all
Procedure test1()
Protected b.i = 1
Protected c.i = 0
Protected d.i = 0
Protected e.i = 0
Protected f.i = 0
Protected g.i = 0
; Insert Code here...
EndProcedure
test1()
The Proc compiles to this:
Code: Select all
_Procedure0:
PS0=28
XOR eax,eax ; initialize all local variables to 0:
PUSH eax
PUSH eax
PUSH eax
PUSH eax
PUSH eax
PUSH eax
; Protected b.i = 1
MOV dword [esp],1
; Protected c.i = 0
MOV dword [esp+4],0 ; duplicate the initialization of variables to 0:
; Protected d.i = 0
MOV dword [esp+8],0
; Protected e.i = 0
MOV dword [esp+12],0
; Protected f.i = 0
MOV dword [esp+16],0
; Protected g.i = 0
MOV dword [esp+20],0
The coder is punished for exercising good programming practice of initializing every variable before use, because in this example, they are all initialized TWICE!
And regarding the previous example with the a/4 + b/4 vs (a+b) >> 2, that is the difference between a strong optimizing compiler (It does it automatically for you!) vs. one with NO optimizing, which requires YOU to code it all in a way that ends up more optimized. The biggest problem with this is that VERY FEW PB coders know how to even SEE the asm code, much less actually analyze it. Also, very few understand why one code snip compiles more efficiently than another. An optimizing compiler takes care of all of this for you so it just doesn't matter--the coder can be naive, and blissfully so, since the end result is about the same. Not so with PB; since its primary focus is beginners, who are still naive about these manual optimizations, it merrily produces poor code because of the skillset of the coder base.
And YES, it
IS SLOWER. How much slower may very well be irrelevant, in most situations. Consider if you are calculating an internal window size after a major window resize; nobody will notice a dozen extra instructions being executed, even on a slow cpu.
On the other hand, if you are performing numerous CPU-intensive calculations, those dozen extra instructions could easily turn into minutes, if not hours given a large enough task.