title: c++ timing same loop gives different results
body: <p>Can someone explain why running this code multiple times gives very variable results?
  Unless I did something wrong, it should measure the time my system (MacOSX Sierra, Xcoe9.2) takes to run an empty for loop 1000 times. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;chrono&gt;
  
  void printstuff (){
      for (int i = 0; i &lt; 1000; ++i){
      //empty loop
      }
  }
  
  int main(int argc, const char * argv[]) {
  
      auto time1 = std::chrono::high_resolution_clock::now();
      printstuff();
      auto time2 = std::chrono::high_resolution_clock::now();
  
      std::cout &lt;&lt; std::chrono::duration_cast&lt;std::chrono::nanoseconds&gt;(time2 - time1).count() &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>