title: Ternary operator is twice as slow as an if-else block?
body: <p>I read everywhere that ternary operator is supposed to be faster than, or at least the same as, its equivalent <code>if</code>-<code>else</code> block.</p>
  
  <p>However, I did the following test and found out it's not the case:</p>
  
  <pre><code>Random r = new Random();
  int[] array = new int[20000000];
  for(int i = 0; i &lt; array.Length; i++)
  {
      array[i] = r.Next(int.MinValue, int.MaxValue);
  }
  Array.Sort(array);
  
  long value = 0;
  DateTime begin = DateTime.UtcNow;
  
  foreach (int i in array)
  {
      if (i &gt; 0)
      {
          value += 2;
      }
      else
      {
          value += 3;
      }
      // if-else block above takes on average 85 ms
  
      // OR I can use a ternary operator:
      // value += i &gt; 0 ? 2 : 3; // takes 157 ms
  }
  DateTime end = DateTime.UtcNow;
  MessageBox.Show("Measured time: " + (end-begin).TotalMilliseconds + " ms.\r\nResult = " + value.ToString());
  </code></pre>
  
  <p>My computer took 85 ms to run the code above. But if I comment out the <code>if</code>-<code>else</code> chunk, and uncomment the ternary operator line, it will take about 157 ms.</p>
  
  <p>Why is this happening?</p>