title: Is clock_gettime() correctly implemented in MinGW GCC 8.2.0?
body: <p>By chance, I found out about the existence of the <code>clock_gettime()</code> function for Linux systems. Since I'm looking for a way to measure execution time of a function, I tried it in the MinGW gcc 8.2.0 version on a Windows 10 64-bit machine:</p>
  
  <pre><code>#include &lt;time.h&gt;
  #include &lt;stdio.h&gt;
  
  int main() {
      struct timespec tstart, tend;
      clock_gettime(CLOCK_THREAD_CPUTIME_ID, &amp;tstart);
      for (int i = 0; i &lt; 100000; ++i);
      clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;tend);
      printf("It takes %li nanoseconds for 100,000 empty iterations.\n", tend.tv_nsec - tstart.tv_nsec);
      return 0;
  }
  </code></pre>
  
  <p>This code snippet compiles without warnings/errors, and there are no runtime failures (at least not written to stdout).</p>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>It takes 0 nanoseconds for 100,000 empty iterations.
  </code></pre>
  
  <p>Which I don't believe is true.</p>
  
  <p>Can you spot the flaw?</p>
  
  <hr>
  
  <p>One more thing:</p>
  
  <p>According to the <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf" rel="nofollow noreferrer">N1570 Committee draft</a> (April 12, 2011) of the ISO/IEC 9899:201x, shouldn't <code>timespec_get()</code> take the role of <code>clock_gettime()</code> instead?</p>