title: Reasons for variations in run-time performance of identical code
body: <p>when running some benchmarks of my C++ software, I obtained the following picture:  <a href="https://i.stack.imgur.com/k179H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k179H.png" alt="enter image description here"></a></p>
  
  <p>The plot shows the execution time in nanoseconds of one tick of the software. 
  The exact same tick is ran each time (one data point is one tick). </p>
  
  <p>When testing in the simulated environment of valgrind, there is zero difference between each tick, and I don't have syscalls others than what <code>clock_gettime</code> may do.</p>
  
  <p>I would like to understand what can cause the two "speeds" in which the tick seems to run. I disabled intel CPU sleep states which greatly helped (before that I had 4 lines like this), and what could be the causes for the outlier points. The scheduler used is linux's FIFO scheduler.</p>
  
  <p>An interesting observation is that the tick times alternate between the two values of 9000 and 6700 ns; here's some data points: </p>
  
  <pre><code>9022
  6605
  9170
  6756
  9126
  6594
  9102
  6744
  9016
  6643
  8950
  6638
  9047
  6662
  </code></pre>
  
  <p>edit: 
  just doing this in a loop in my thread: </p>
  
  <pre><code>auto t0 = std::chrono::high_resolution_clock::now();
  auto t1 = std::chrono::high_resolution_clock::now();
  measure(std::chrono::duration_cast&lt;std::chrono::nanoseconds&gt;(t1 - t0).count()));
  </code></pre>
  
  <p>is enough for me to see the alternating effect, though between 100 and 150 ns.</p>