Difference? myDate.Equals(Date.MinValue) -or- myDate = Date.MinValue

A

Andreas Klemt

Hello,
what is the difference and what is better (performance etc) ?

a) If myDate.Equals(Date.MinValue)
b) If myDate = Date.MinValue

Thanks,
Andreas
 
J

Jerry III

Don't know about VB but in C# the operator calls the function. Depending on
the compiler the function might be faster (but most likely it will be the
same as the compiler will do the substitution, much like inline functions in
C++).

Jerry
 
A

Andreas Klemt

Hello,

results are:

a) If myDate.Equals(Date.MinValue)
0,007439

b) If myDate = Date.MinValue
0,002253

Regards,
Andreas
 
N

Natty Gur

Take a look in IL and you will see that CLR use Boxing just for Equals.
Equals should be slower.

//000004: Dim myDate As Date
//000005: If myDate.Equals(Date.MinValue) Then
IL_0001: ldloca.s myDate
IL_0003: ldsfld valuetype [mscorlib]System.DateTime
[mscorlib]System.DateTime::MinValue
IL_0008: box [mscorlib]System.DateTime
IL_000d: call instance bool
[mscorlib]System.DateTime::Equals(object)
IL_0012: brfalse.s IL_0014
//000006:
//000007: End If
IL_0014: nop
//000008: If myDate = Date.MinValue Then
IL_0015: ldloc.0
IL_0016: ldsfld valuetype [mscorlib]System.DateTime
[mscorlib]System.DateTime::MinValue
IL_001b: call int32
[mscorlib]System.DateTime::Compare(valuetype [mscorlib]System.DateTime,

valuetype [mscorlib]System.DateTime)
IL_0020: ldc.i4.0
IL_0021: bne.un.s IL_0023
//000009:
//000010: End If

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top