title: C# : Performance between Delegates and Method Calling
body: <p>Sorry for my bad english.</p>
  
  <p>I have two draw methods, let's say "void Draw1();" and "void Draw2();".
  My application should always call Draw1 if the user check "call the Draw1 function". And therefore, my application should always call Draw2 if the user does not check "call the Draw1 function".</p>
  
  <p>There are two ways to do that :</p>
  
  <ol>
  <li><p>Using delegates function :
  <code>
      delegate void DrawFct();
      DrawFct Draw;
      ...
      Draw = (call_Draw1.Checked) ? new DrawFct(Draw1) : new DrawFct(Draw2);
      ...
      Draw();
      ...
      void Draw1() { ... calls_1 ... }
      void Draw2() { ... calls_2 ... }
  </code></p></li>
  <li><p>Using flags :
  <code>
      bool useDraw1 = call_Draw1.Checked;
      ...
      void Draw()
      {
          if (useDraw1) { ... calls_1 ... }
          else { ... calls_2 ... }
      }
  </code></p></li>
  </ol>
  
  <p>I wanted to know which one was the fastest.
  I make two tests :</p>
  
  <ol>
  <li>With the first method when I debug my application, the call of Draw() is translated in ASM in:<br>
  <code>
  000007FE8FF3A393  mov         rax,qword ptr [rbp+0FA0h]
  000007FE8FF3A39A  mov         rax,qword ptr [rax+1B8h]
  000007FE8FF3A3A1  mov         qword ptr [rbp+0F58h],rax
  000007FE8FF3A3A8  mov         rcx,qword ptr [rbp+0F58h]
  000007FE8FF3A3AF  mov         rcx,qword ptr [rcx+8]
  000007FE8FF3A3B3  mov         rax,qword ptr [rbp+0F58h]
  000007FE8FF3A3BA  call        qword ptr [rax+18h]
  000007FE8FF3A3BD  nop
  </code></li>
  <li>In the second method, the call to Draw() is simply :<br>
  <code>
  000007FE8FF3A386  mov         rcx,qword ptr [rbp+0FA0h]
  000007FE8FF3A38D  call        000007FE8FDFD2E0
  000007FE8FF3A392  nop
  </code>  </li>
  </ol>
  
  <p>Of course, in the second method, I have one more check after the call. But in the end, the second method is faster than the first one...</p>
  
  <p>Do you know another method to do what I want ? or perhaps some tricks to make the call of a delegate lighter ?</p>
  
  <p>Thank you.</p>