title: C: Different implementation of clock() in Windows and other OS?
body: <p>I had to write a very simple console program for university that had to measure the time required to make an input.</p>
  
  <p>Therefor I used <code>clock()</code> in front and after an <code>fgets()</code>call. When running on my Windows computer it worked perfectly. However when running on my friends Mac-Book and Linux-PC it gave extremely small results (a few micro seconds of time only).</p>
  
  <p>I tried the following code on all 3 OS:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  #include &lt;unistd.h&gt;
  
  void main()
  {
      clock_t t;
  
      printf("Sleeping for a bit\n");
  
      t = clock();
  
      // Alternatively some fgets(...)
      usleep(999999);
  
      t = clock() - t;
  
      printf("Processor time spent: %lf", ((double)t) / CLOCKS_PER_SEC);
  }
  </code></pre>
  
  <p>On windows the output shows 1 second (or the amount of time you took to type when using <code>fgets</code>), on the other two OS not much more than 0 seconds.</p>
  
  <p>Now my question is why there is such a difference in implementation of <code>clock()</code> on these OS. For windows it seems like the clock keeps ticking while the thread is sleeping/waiting but for Linux and Mac isn't?</p>
  
  <p>Edit:
  Thank you for the answers so far guys, so it's just Microsoft's faulty implementation really.</p>
  
  <p>Could anyone please answer my last question:</p>
  
  <p><strong>Also is there a way to measure what I wanted do measure on all 3 systems using C-standard libraries since <code>clock()</code> only seems to work this way on Windows?</strong></p>