Re: What is faster?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hal Rosser wrote:
>
> "MikeD" <nobody@xxxxxxxxxxx> wrote in message
> news:e%23M6DQdqFHA.564@xxxxxxxxxxxxxxxxxxxxxxx
> >
> > "Hal Rosser" <hmrosser@xxxxxxxxxxxxx> wrote in message
> > news:enqPe.540$7F.510@xxxxxxxxxxxxxxxxxxxxxxxxx
> > > I'm not sure which is faster, but aren't you being redundant by checking
> > if
> > > the boolean = true or false ?
> > > A boolean stands by itself as a condition.
> > >
> > > If bResult Then
> > > '//## Do something
> > > End If
> >
> >
> > There's still an implicit comparison being done. There's no measureable
> > difference between 'If bResult Then' and 'If bResult = True Then'. For
> that
> > matter, they might even compile identically.
> >
> > If you really want to be nitpicky, your statement that a boolean stands by
> > itself as a condition is really rather limiting. So can a Long, or an
> > Integer, or anything else. The following is valid code:
> >
> > Dim A As Long
> > If A Then
> > 'Do something
> > End If
> >
> > --
> > Mike
> > Microsoft MVP Visual Basic
>
> I accept your statement as gospel, in that there is no measurable difference
> with or without the "= True" after a boolean variable in an "If" statement.
> You are probably more experienced than me and probably can program circles
> around me, - but I still think that adding "= True" after a boolean
> variable in an "If" statement is being redundant. That is just my opinion -
> and I probably will not change it in the near future. Giving the variable a
> name beginning with "is" also goes along with this 'philosophy'.
>
> If blnIsValidEmail Then
> '#// yadda yadda
> End If
>
> Your example of using a numeric variable as a boolean condition made me
> shudder. :-)

You're mistaking (or at least mixing up) the difference between source
statements and the implementation of that source code into machine
instructions.

>From the standpoint of <source>, yes, you can consider the "=Value"
portion of a Boolean test as redundant or superfluous. But, as Mike is
pointing out, what has to happen for that test to be performed is for
that source code to be translated into machine instructions.

What is required for the proper evaluation of the expression "If bVar
Then" is that for any non-zero value of vBar the following construct
statements are to be executed. That is and can only be done by the
compiler evaluating the condition

If vBar <> 0 Then

Thus, the condition is actually compiled, probably into a BNE machine
instruction (although I've not actually looked at VB compiler-generated
code to verify which way it builds If...Then constructs). For that BNE
instruction there also is a register value it's compared against.

So, the point of all the above rather long-winded rambling is to remind
you to not equate brevity of <source code> with necessarily shorter
(either in size or speed) compiled code.

HTH...
.



Relevant Pages

  • Re: C++/TCL Need Solution to Compile Error c2784
    ... There's always the "Platform SDK" from MSDN if you need the window.h stuff, ... Since I'm using the Command Prompt rather than the GUI to compile the ... I then tried to compile your source code and I kept getting the same ...
    (comp.lang.tcl)
  • Re: Debugging Newbie Question
    ... The CLR does not understand this source code and so before it ... ASP.NET, however, ASP.NET will compile your page's source code and cache ... the debugger will have IL and x86 created from ... in release mode assemblies. ...
    (microsoft.public.dotnet.faqs)
  • Re: Debugging Newbie Question
    ... The CLR does not understand this source code and so before it ... ASP.NET will compile your page's source code and cache the result ... > does this so that a debugger can attach to the code and allow you to step ... > release mode assemblies. ...
    (microsoft.public.dotnet.faqs)
  • The curse of constant fields
    ... feature in the Java language, and decided to write up about it. ... in a class, compile the changed class, and run the code manually to ... A quick search through the source code shows that there is no other ... This is true even if the usage itself is not ...
    (comp.lang.java.programmer)
  • Re: creaping coupling......
    ... In C++ it would be trivial to break that source code dependency, ... When you compile a .java module, ... In Java and C# it's asserted at compile time. ...
    (comp.object)