title: perf stat gives different number of instruction for every run
body: <p>I ran perf analysis on the following empty program,</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
  }
  </code></pre>
  
  <p>After compiling and running perf stat ./a.out I got the following output saying (along with other data like number of cycles, task-clock etc):</p>
  
  <pre><code>418,869 instructions # 0.87 insns per cycle
  </code></pre>
  
  <p>The number of instructions changes during every 'perf' analysis on the same elf. </p>
  
  <p>My actual need is to find the number of instructions in a particular function I wrote. So I will be subtracting the above number from the number of instructions in the new program.(I could count the number of line in program.s created using -S tag in gcc but I'm confused after looking at perf behaviour)</p>
  
  <p>Why is the number of instructions not consistent, to be exact not same?</p>
  
  <p><strong>Update</strong>
  I followed the example given in <a href="http://linux.die.net/man/2/perf_event_open" rel="noreferrer">man page</a> to use perf_event_open() in C </p>