title: Windows 7 timing functions - How to use GetSystemTimeAdjustment correctly?
body: <p>I ran some tests using the <code>GetSystemTimeAdjustment</code> function on Windows 7, and got some interesting results which I cannot explain. As fas as I understand, this method should return if the system time is synchronized periodically and if it is, at which interval and with which increment it is updated (<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724394%28v=vs.85%29.aspx">see GetSystemTimeAdjustment function on MSDN</a>). </p>
  
  <p>From this I follow that if I query the system time for example using <code>GetSystemTimeAsFileTime</code> repeatingly I should either get no change (the system clock has not been updated), or a change which is a multiple of the increment retrieved by <code>GetSystemTimeAdjustment</code>. <strong>Question one:</strong> Is this assumption correct?</p>
  
  <p>Now consider the following testing code:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  int main()
  {
      FILETIME fileStart;
      GetSystemTimeAsFileTime(&amp;fileStart);
      ULARGE_INTEGER start;
      start.HighPart = fileStart.dwHighDateTime;
      start.LowPart = fileStart.dwLowDateTime;
  
      for (int i=20; i&gt;0; --i)
      {
          FILETIME timeStamp1;
          ULARGE_INTEGER ts1;
  
          GetSystemTimeAsFileTime(&amp;timeStamp1);
  
          ts1.HighPart = timeStamp1.dwHighDateTime;
          ts1.LowPart  = timeStamp1.dwLowDateTime;
  
          std::cout &lt;&lt; "Timestamp: " &lt;&lt; std::setprecision(20) &lt;&lt; (double)(ts1.QuadPart - start.QuadPart) / 10000000 &lt;&lt; std::endl;
  
      }
  
      DWORD dwTimeAdjustment = 0, dwTimeIncrement = 0, dwClockTick;
      BOOL fAdjustmentDisabled = TRUE;
      GetSystemTimeAdjustment(&amp;dwTimeAdjustment, &amp;dwTimeIncrement, &amp;fAdjustmentDisabled);
  
      std::cout &lt;&lt; "\nTime Adjustment disabled: " &lt;&lt; fAdjustmentDisabled
          &lt;&lt; "\nTime Adjustment: " &lt;&lt; (double)dwTimeAdjustment/10000000
          &lt;&lt; "\nTime Increment: " &lt;&lt; (double)dwTimeIncrement/10000000 &lt;&lt; std::endl;
  
  }
  </code></pre>
  
  <p>It takes 20 timestamps in a loop and prints them to the console. In the end it prints the increment with which the system clock is updated. I would expect the differences between the timestamps printed in the loop to be either 0 or multiples of this increment. However, I get results like this:</p>
  
  <pre><code>Timestamp: 0
  Timestamp: 0.0025000000000000001
  Timestamp: 0.0074999999999999997
  Timestamp: 0.01
  Timestamp: 0.012500000000000001
  Timestamp: 0.014999999999999999
  Timestamp: 0.017500000000000002
  Timestamp: 0.022499999999999999
  Timestamp: 0.025000000000000001
  Timestamp: 0.0275
  Timestamp: 0.029999999999999999
  Timestamp: 0.032500000000000001
  Timestamp: 0.035000000000000003
  Timestamp: 0.040000000000000001
  Timestamp: 0.042500000000000003
  Timestamp: 0.044999999999999998
  Timestamp: 0.050000000000000003
  Timestamp: 0.052499999999999998
  Timestamp: 0.055
  Timestamp: 0.057500000000000002
  
  Time Adjustment disabled: 0
  Time Adjustment: 0.0156001
  Time Increment: 0.0156001
  </code></pre>
  
  <p>So it appears that the system time is updated using an interval of about 0.0025 seconds and not 0.0156 seconds as return by <code>GetSystemTimeAdjustment</code>. </p>
  
  <p><strong>Question two:</strong> What is the reason for this?</p>