title: How to cancel branch prediction?
body: <p>From reading <a href="https://software.intel.com/en-us/articles/avoiding-the-cost-of-branch-misprediction%20%22%22" rel="noreferrer">this</a> I came across the next two quotes:</p>
  
  <p><strong>First quote:</strong></p>
  
  <blockquote>
    <p>A typical case of unpredictable branch behavior is when the comparison result is dependent on data.</p>
  </blockquote>
  
  <p><strong>Second quote:</strong></p>
  
  <blockquote>
    <p>No Branches Means No Mispredicts</p>
  </blockquote>
  
  <p>For my project, I work on a dependent data and I perform many <code>if</code> and <code>switch</code> statements. My project is related to <code>Big Data</code> so it has to be as efficient as possible. So I wanted to test it on the data provided by user, to see if branch prediction actually slows down my program or helps. As from reading <a href="https://en.wikipedia.org/wiki/Branch_predictor%20%22%22" rel="noreferrer">here</a>:</p>
  
  <blockquote>
    <p>misprediction delay is between 10 and 20 clock cycles.</p>
  </blockquote>
  
  <p>What shocked me most was:</p>
  
  <blockquote>
    <p>Removing the branches not only improves runtime performance of the code, it also helps the compiler to optimize the code.</p>
  </blockquote>
  
  <p>Why use branch prediction then ?</p>
  
  <p>Is there a way to force the compiler to generate assembly code without branches ? or to disable branch prediction so that CPU? so I can compare both results ?</p>