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/yetOptimization.pdf
Hope this helps
Jay
A Traveler said:
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.