Re: What is faster?
- From: Duane Bozarth <dpbozarth@xxxxxxxxxxxx>
- Date: Fri, 26 Aug 2005 19:17:50 -0500
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...
.
- References:
- Re: What is faster?
- From: Hal Rosser
- Re: What is faster?
- From: MikeD
- Re: What is faster?
- From: Hal Rosser
- Re: What is faster?
- Prev by Date: Save PictureBox contents to a bitmap
- Next by Date: Re: Save PictureBox contents to a bitmap
- Previous by thread: Re: What is faster?
- Next by thread: Re: What is faster?
- Index(es):
Relevant Pages
|