Dave,
Looking at the IL (with ILDASM.EXE) I would expect #2 to be faster. As
IsNothing involves calling 2 runtime routines:
//000036: If IsNothing(_myVar) Then
IL_0009: ldloc.0
IL_000a: call object
[mscorlib]System.Runtime.CompilerServices.RuntimeHelpers::Ge tObjectValue(object)
IL_000f: call bool
[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(objec t)
IL_0014: brfalse.s IL_0016
//000037:
//000038: End If
IL_0016: nop
//000039:
//000040: If _myVar Is Nothing Then
IL_0017: ldloc.0
IL_0018: brtrue.s IL_001a
//000041:
//000042: End If
IL_001a: nop
However! the JIT compiler may or may not inline one or both of those calls.
So the actual performance difference may not be worth worrying about.
Remember the 80/20 rule. 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).
The use of the List(Of T) may well be outside this 20% of your code,
prematurely optimizing it is possibly a waste of time.
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
In other words if you find IsNothing(_myVar) to be more readable then _myVar
Is Nothing, then go ahead & use it. When IsNothing(_myVar) is proven to be a
performance problem in a specific routine via profiling, then I would change
that routine to use Is Nothing.
Hope this helps
Jay
"Dave Taylor" <no**********@processeng.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
| This is really not very important but something that I'm just curious
| about...which is faster to execute or are they the same:
|
| (1) If IsNothing(_myVar) Then ...
|
| or
|
| (2) If _myVar Is Nothing Then ...
|
| I find myself using #1 most frequently but for no real reason other than I
| like the way it looks.
|
| -- Dave
|
|