473,480 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IsNothing(_myVar) vs. _myVar Is Nothing

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
Nov 21 '05 #1
4 1674
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
|
|
Nov 21 '05 #2
Dave,

To tell the same as Jay in other words.

The IsNothing is a function in the Microsoft.VisualBasic namespace. The
Microsoft.VisualBasic namespace is a namespace included in the framework and
although it is named Microsoft.VisualBasic namespace usable by every managed
program language (C#, J# and C++ managed).

It gives a lot of handy functions, often it are *only* wrappers around
functions in System.Net while mostly it includes as well optimizing code
(even if that optimizing is helping you to write less code).

Here is as Jay showed by the ILS probably nothing more than a wrapper.

About the 80/20 I agree completly with Jay.

http://msdn.microsoft.com/library/de...rykeywords.asp

I hope this explains it even more.

Cor

"Dave Taylor" <no**********@processeng.com> schreef in bericht
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

Nov 21 '05 #3
just test it:
this tool is great, easy to use (even I was able, hehe) and free: DevPartner
Profiler
http://www.compuware.com/products/de...01181D03071E04

"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

Nov 21 '05 #4
Dave,
I should add, that I would attempt to be consistent with the project,
solution, team, department, & company. On whether I used (1) or (2).
For example: In new projects/solutions that I create I normally use (2).
However if I inherited a solution that used (1), I would probably continue
using (1) in that project...
FWIW: In VB 2005 (aka Whidbey, due out in Nov 2005) a new IsNot operator is
being introduced which lends itself well to the syntax of (2).

VS 2005 info:
http://lab.msdn.microsoft.com/vs2005/

IsNot operator:
http://msdn2.microsoft.com/library/t...us,vs.80).aspx
Of course with (1) you can simply use "Not IsNothing(_myVar)" instead...
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
|
|
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
21013
by: Jim Heavey | last post by:
I am trying to transition from VB.Net - what is the equivalent if the IsNothing()? Thanks in advance for your assistance!!!!!!!!!
12
44867
by: Steve Peterson | last post by:
Hi - just a quick question. I was wondering which is the better "VB.Net" way - to use IsNothing or the Is Nothing in an If..Then statement For example: If IsNothing(myObject) then 'blah...
5
2052
by: John A Grandy | last post by:
do these mean the same thing ? Dim s As String ..... If s Is Nothing Then ..... If s = Nothing Then .....
4
2389
by: tinman | last post by:
Hi.... There appears to be another way of checking if an object IsNothing in ..NET.....was wondering if this approach is better than the classic VB6 way of checking Is Nothing ? Example...
8
17491
by: MattB | last post by:
Hello. I have a vb.net (asp.net) application that uses ado.net datasets. At one point, I need to check a text field in a DataTable to see if there's any text in it before performing text operations...
3
11661
by: Larry | last post by:
Hi all, I am coming over from VB 6, learning VB.NET. I have read and have in front of me, the language reference from the msdn, on; Behavior of Null has changed, Isdbnull function and...
7
1584
by: andreas | last post by:
Can someone tell me 1) Is there a difference between closing or disposing a reference data type 2) about nothing dim fr as form2 isnothing(fr) gives true
11
1689
by: Jethro | last post by:
Hi guys, quick sanity check please. When TESTING for nothing, it's "if <exprIs Nothing" when ASSIGNING, it's "<expr= Nothing" correct ? so a line "If ThisValue = nothing" in some...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
170
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.