Arthur,
In addition to my other comments, you can use ILDASM.EXE to look at the IL
created.
//000131: Dim b1 As Boolean
//000132: Dim b2 As Boolean
//000133: If b1 And b2 Then
IL_0013: ldloc.0
IL_0014: ldloc.1
IL_0015: and
IL_0016: brfalse.s IL_0018
//000134:
//000135: End If
IL_0018: nop
//000136: If b1 AndAlso b2 Then
IL_0019: ldloc.0
IL_001a: brfalse.s IL_001f
IL_001c: ldloc.1
IL_001d: brfalse.s IL_001f
//000137:
//000138: End If
IL_001f: nop
The other thing to consider is what will the JIT do to the IL when it
creates the machine executable code.
IMHO this question really falls into the 80/20 rule category. That is 80% of
the execution time of your program is spent in 20% of your code. I will
optimize (worry about performance, memory consumption) the 20% once that 20%
has been identified & proven to be a performance problem via profiling (CLR
Profiler is one profiling tool).
For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf
Hope this helps
Jay
"A Traveler" <hitchhikersguideto-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Yes, i am aware that if the conditions are negligible, it doesnt make
> *practical* sense to bother with short circuiting.
> I am not looking for a practical answer to a specific problem though. I am
> simply asking whether there are certain conditions (such as hit
> percentages) under which an And performs better than AndAlso, due simply
> to the way _And_ is implemented vs. how _AndAlso_ is implemented. And i
> dont mean for a single run, but over the course of a large number of runs,
> where sometimes it will short circuit and sometimes it wont.
>
>
>
> "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
> news:(E-Mail Removed)...
>>A Traveler wrote:
>>> I dont think i was clear in my question...
>>>
>>> I know _both_ OrElse and AndAlso are short-circuit. But take a case
>>> where the time to process the individual conditions is negligible and
>>> can be discounted. Then assume that you will break out on the
>>> short-circuit only on avg about half the time (or less). Will the
>>> Also/Else save time in the long run then?
>>
>> As an innocent bystander just browsing this group, I have to add...
>>
>> "time to process the individual conditions is negligible"
>>
>> If that's the case, then there's no benefit to short circuits. When the
>> tests do take considerable time, it makes sense. The code below will
>> obviously benefit from a short circuit.
>>
>> If ResultsFromHardDriveSearch(SomeSearchTerm) > 0 And
>> ResultsFromInternetSearch(SomeSearchTerm) > 0 Then
>>
>> On the other hand, the code below won't benefit much.
>>
>> If X = 1 Or X = 2 Then
>>
>> fwiw, you can short circuit VB6 by replacing If/Then's with Select Case's
>>
>> --
>> Ken Halter - MS-MVP-VB - http://www.vbsight.com
>> Please keep all discussions in the groups..
>
>