title: why is C# performance slower than VB
body: <p>I have two library,  first one is the original which was done in vb.net, second one is in c#.</p>
  
  <p>doing exactly the same thing.</p>
  
  <p>vb.net is about 10% faster than c# which is very strange</p>
  
  <p>so what I have found that seem the cause of the slowdown, by looking at <code>IL</code> code of both is(i would say that close to 99% of the <code>il</code> code is the same);</p>
  
  <ol>
  <li><p>in c# all method call have <code>hidebysig</code> but not in vb.net</p>
  
  <p>is this one thing that could be a performance issue?</p></li>
  <li><p>in c# you must initialize a local variable before using it</p>
  
  <p>this wont work in c#</p>
  
  <pre><code>void test()
  {
      int a;
      a += 1;
  }
  </code></pre>
  
  <p>this will</p>
  
  <pre><code>void test()
  {
      int a = 0;
      a += 1;
  }
  </code></pre>
  
  <p>while this work in vb.net</p>
  
  <pre><code>Sub test()
     Dim a As Integer
     a += 1
  End Sub
  </code></pre>
  
  <p>which in c# cause 2 more IL line which, I'm pretty sure, cause a performance issue</p></li>
  <li><p>in vb.net it seem I cannot get the <code>il</code> code to use <code>call</code>, it always use <code>callvirt</code> while c# always use <code>call</code></p>
  
  <p>is this one thing that could be a performance issue?</p></li>
  <li><p>.maxstack is sometime bigger in c#</p>
  
  <p>is this one thing that could be a performance issue?</p></li>
  </ol>
  
  <p>in the end, I'm trying to understand how to get back that 10% speed loss. So far I'm clueless</p>
  
  <p>if you want to take a look here it is, you can decompile it yourself, i used ilspy;</p>
  
  <p><a href="http://pages.videotron.com/spirch/bench.zip" rel="nofollow">ZIP file, compiled version</a><br>
  <a href="http://pages.videotron.com/spirch/bench/ChessEngine.dll" rel="nofollow">ChessEngine.dll</a><br>
  <a href="http://pages.videotron.com/spirch/bench/ChessEngine.dll" rel="nofollow">ChessEngineSharp.dll</a><br>
  <a href="http://pages.videotron.com/spirch/bench/ChessEngine.dll" rel="nofollow">ConsoleApplication1.exe</a></p>