title: Does `clock` measure `sleep` i.e. suspended threads?
body: <p>I am trying to understand the <code>clock_t clock(void);</code> function better and have following question:</p>
  <p>Did I understand that correctly that <code>clock</code> measures the number of ticks of a process since it is <strong>actively running</strong> and <code>sleep</code> suspends the calling thread – in this case there is only one thread, namely the main-thread – and therefore suspends the whole process. Which means that <code>clock</code> does not measure the cpu-time (ticks) of the process, since it is not actively running?<br />
  If so what is the recommended way to measure the actual needed time?</p>
  <p>&quot;The <code>clock()</code> function returns an approximation of processor time used by the program.&quot; <a href="https://linux.die.net/man/3/clock" rel="nofollow noreferrer">Source</a><br />
  &quot;The CPU time (process time) is measured in clock ticks or seconds.&quot; <a href="https://en.wikipedia.org/wiki/CPU_time" rel="nofollow noreferrer">Source</a><br />
  &quot;The number of clock ticks per second can be obtained using: <code>sysconf(_SC_CLK_TCK);</code>&quot; <a href="https://linux.die.net/man/2/times" rel="nofollow noreferrer">Source</a></p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;  // printf
  #include &lt;time.h&gt;   // clock
  #include &lt;unistd.h&gt; // sleep
  
  int main()
  {
    printf(&quot;ticks per second: %zu\n&quot;, sysconf(_SC_CLK_TCK));
  
    clock_t ticks_since_process_startup_1 = clock();
    sleep(1);
    clock_t ticks_since_process_startup_2 = clock();
  
    printf(&quot;ticks_probe_1:    %zu\n&quot;, ticks_since_process_startup_1);
    printf(&quot;sleep(1);\n&quot;);
    printf(&quot;ticks_probe_2:    %zu\n&quot;, ticks_since_process_startup_2);
    printf(&quot;ticks diff:       %zu &lt;-- should be 100\n&quot;, ticks_since_process_startup_2 - ticks_since_process_startup_1);
    printf(&quot;ticks diff sec:   %Lf &lt;-- should be 1 second\n&quot;, (long double)(ticks_since_process_startup_2 - ticks_since_process_startup_1) / CLOCKS_PER_SEC);
    return 0;
  }
  </code></pre>
  <p><strong>Resulting Output:</strong></p>
  <pre><code>ticks per second: 100
  ticks_probe_1:    603
  sleep(1);
  ticks_probe_2:    616
  ticks diff:       13 &lt;-- should be 100
  ticks diff sec:   0.000013 &lt;-- should be 1 second
  </code></pre>