Re: IsNothing(_myVar) vs. _myVar Is Nothing

Tech-Archive recommends: Fix windows errors by optimizing your registry



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::GetObjectValue(object)
IL_000f: call bool
[Microsoft.VisualBasic]Microsoft.VisualBasic.Information::IsNothing(object)
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/yetOptimization.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_spam_dave@xxxxxxxxxxxxxx> wrote in message
news:%23MZT1v2oFHA.1872@xxxxxxxxxxxxxxxxxxxxxxx
| 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
|
|


.



Relevant Pages

  • Re: Converting Vplus to .Net
    ... Hmm, interesting code, Dave, and it looks fun. ... this routine would perform the Vreadfields which basically blocks ... Public Function VreadFields(ByVal comArea As ComAreaDefinition) As ... To join/leave the list, search archives, change list settings, * ...
    (comp.sys.hp.mpe)
  • Re: For Those Who Dont Believe Michael Jackson and Sony Didnt Pimp Out Beatles Music to Recoup Debt
    ... witch" routine. ... When Dave continues his Jewish remarks, she will quickly turn on him. ... What matters is not whether he attacks Jews, ...
    (rec.music.beatles)
  • Re: Message Default file Location
    ... Copied and pasted response from Dave. ... I think we turned the 'thread corner' because the Backup Utility did not ... If I change the default file location as suggested my many, the files simply move there, and when I run the BU routine, it just asks for a BU file location again, neither does it provide me a way to do that. ... first create a folder in the location you require. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: For Those Who Dont Believe Michael Jackson and Sony Didnt Pimp Out Beatles Music to Recoup Debts
    ... RichL wrote: ... She will at some point launch her "everybody picks on me" routine ... She will start bombarding them with the "Yoko = evil witch" ... When Dave continues his Jewish remarks, she will quickly turn on him. ...
    (rec.music.beatles)
  • Re: Possible F77 Code Improvement ??
    ... If profiling the code is a "distraction to say the least", why would you even ask about optimising your code in the first place? ... How can you be sure the routine in question is the slow spot if you haven't profiled the code? ... program is spending a lot of time in Sub EFFECT5." ...
    (comp.lang.fortran)