Guest User

Comparing Math.Min and If with two >

a guest
Jun 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 KB | None | 0 0
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         DateTime a = new DateTime(100);
  6.         DateTime b = new DateTime(200);
  7.         DateTime c = new DateTime(50);
  8.         Console.WriteLine(mathmin(a, b, c)  + " " + ifmin(a, b, c));
  9.     }
  10.  
  11.     static bool MathMin(DateTime a, DateTime b, DateTime c)
  12.     {
  13.         return Math.Min(a.Ticks, b.Ticks) > c.Ticks;
  14.     }
  15.  
  16.     static bool IfMin(DateTime a, DateTime b, DateTime c)
  17.     {
  18.         return a > c && b > c;
  19.     }
  20. }
  21.  
  22. IL-Instructions MathMin
  23.  
  24. 0   0000    nop
  25. 1   0001    ldarga.s    a (0)
  26. 2   0003    call    instance int64 [mscorlib]System.DateTime::get_Ticks()
  27.     0   0000    ldarg.0
  28.     1   0001    ldfld   uint64 System.DateTime::dateData
  29.     2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  30.     3   000F    and
  31.     4   0010    ret
  32. 3   0008    ldarga.s    b (1)
  33. 4   000A    call    instance int64 [mscorlib]System.DateTime::get_Ticks()
  34.     0   0000    ldarg.0
  35.     1   0001    ldfld   uint64 System.DateTime::dateData
  36.     2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  37.     3   000F    and
  38.     4   0010    ret
  39. 5   000F    call    int64 [mscorlib]System.Math::Min(int64, int64)
  40.     0   0000    ldarg.0
  41.     1   0001    ldarg.1
  42.     2   0002    ble.s   5 (0006) ldarg.0
  43.     3   0004    ldarg.1
  44.     4   0005    ret
  45.     5   0006    ldarg.0
  46.     6   0007    ret
  47. 6   0014    ldarga.s    c (2)
  48. 7   0016    call    instance int64 [mscorlib]System.DateTime::get_Ticks()
  49.     0   0000    ldarg.0
  50.     1   0001    ldfld   uint64 System.DateTime::dateData
  51.     2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  52.     3   000F    and
  53.     4   0010    ret
  54. 8   001B    cgt
  55. 9   001D    stloc.0
  56. 10  001E    br.s    11 (0020) ldloc.0
  57. 11  0020    ldloc.0
  58. 12  0021    ret
  59.  
  60. => 34 Instructions
  61.  
  62.  
  63. IL-Instructions IfMin
  64.  
  65. 0   0000    nop
  66. 1   0001    ldarg.0
  67. 2   0002    ldarg.2
  68. 3   0003    call    bool [mscorlib]System.DateTime::op_GreaterThan(valuetype [mscorlib]System.DateTime, valuetype [mscorlib]System.DateTime)
  69.     0   0000    ldarga.s    t1 (0)
  70.     1   0002    call    instance int64 System.DateTime::get_InternalTicks()
  71.         0   0000    ldarg.0
  72.         1   0001    ldfld   uint64 System.DateTime::dateData
  73.         2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  74.         3   000F    and
  75.         4   0010    ret
  76.     2   0007    ldarga.s    t2 (1)
  77.     3   0009    call    instance int64 System.DateTime::get_InternalTicks()
  78.         0   0000    ldarg.0
  79.         1   0001    ldfld   uint64 System.DateTime::dateData
  80.         2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  81.         3   000F    and
  82.         4   0010    ret
  83.     4   000E    cgt
  84.     5   0010    ret
  85. 4   0008    brfalse.s   9 (0013) ldc.i4.0
  86. 5   000A    ldarg.1
  87. 6   000B    ldarg.2
  88. 7   000C    call    bool [mscorlib]System.DateTime::op_GreaterThan(valuetype [mscorlib]System.DateTime, valuetype [mscorlib]System.DateTime)
  89.     0   0000    ldarga.s    t1 (0)
  90.     1   0002    call    instance int64 System.DateTime::get_InternalTicks()
  91.         0   0000    ldarg.0
  92.         1   0001    ldfld   uint64 System.DateTime::dateData
  93.         2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  94.         3   000F    and
  95.         4   0010    ret
  96.     2   0007    ldarga.s    t2 (1)
  97.     3   0009    call    instance int64 System.DateTime::get_InternalTicks()
  98.         0   0000    ldarg.0
  99.         1   0001    ldfld   uint64 System.DateTime::dateData
  100.         2   0006    ldc.i8  0x3FFFFFFFFFFFFFFF
  101.         3   000F    and
  102.         4   0010    ret
  103.     4   000E    cgt
  104.     5   0010    ret
  105. 8   0011    br.s    10 (0014) stloc.0
  106. 9   0013    ldc.i4.0
  107. 10  0014    stloc.0
  108. 11  0015    br.s    12 (0017) ldloc.0
  109. 12  0017    ldloc.0
  110. 13  0018    ret
  111.  
  112. => 45 Instructions
Add Comment
Please, Sign In to add comment