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

  • Thread starter Thread starter Andreas Klemt
  • Start date Start date
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
 
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
 
Hello,

results are:

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

b) If myDate = Date.MinValue
0,002253

Regards,
Andreas
 
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
 
Back
Top