title: Windows Precise Timing : Error in CreateTimerQueueTimer or system_clock::now()?
body: <p>I am working towards achieving +/- ms timing precision. I want the time between threads to be 10ms, but when I measure the time I get something closer to 15ms.</p>
  
  <p>I am trying to understand if the problem is due to the way I am measuring time or if I am measuring the time accurately and there is some delay introduced by  <code>CreateTimerQueueTimer</code></p>
  
  <p>My code looks like </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  #include &lt;chrono&gt;
  #include &lt;ctime&gt;
  using namespace std;
  int current;
  long long* toFill;
  void talk()
      {
      chrono::time_point&lt;chrono::system_clock&gt; tp = \
          chrono::system_clock::now();
      toFill[current++]=chrono::duration_cast&lt;chrono::milliseconds&gt;(tp.time_since_epoch()).count() ;
      }
  
  int _tmain(int argc, _TCHAR* argv[])
      {
      HANDLE hTimer;
      current = 0;
      toFill = new long long[1000];
      CreateTimerQueueTimer(&amp;hTimer,NULL, 
          (WAITORTIMERCALLBACK)talk,NULL,
          0,10,0);
      _sleep(3000);
      DeleteTimerQueueTimer(NULL,hTimer,NULL);
      for (int i = 1;i&lt;current;i++)
          {
          cout &lt;&lt; i &lt;&lt; " : " &lt;&lt; toFill[i]-toFill[i-1]&lt;&lt; endl;
          }
      return 0;
      }
  </code></pre>
  
  <p>Output looks like</p>
  
  <pre><code>...
  161 : 16 &lt;-- Should be 10
  162 : 15
  163 : 16
  164 : 16
  ...
  </code></pre>