Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/clock_gettime.2.html" rel="nofollow noreferrer"><code>clock_gettime</code></a>, which is a POSIX interface to high-resolution timers.</p> <p>If, having read the manpage, you're left wondering about the difference between <code>CLOCK_REALTIME</code> and <code>CLOCK_MONOTONIC</code>, see <a href="https://stackoverflow.com/questions/3523442/difference-between-clock-realtime-and-clock-monotonic">Difference between CLOCK_REALTIME and CLOCK_MONOTONIC?</a></p> <p>See the following page for a complete example: <a href="http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/" rel="nofollow noreferrer">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/</a></p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt; #include &lt;time.h&gt; using namespace std; timespec diff(timespec start, timespec end); int main() { timespec time1, time2; int temp; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;time1); for (int i = 0; i&lt; 242000000; i++) temp+=temp; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;time2); cout&lt;&lt;diff(time1,time2).tv_sec&lt;&lt;":"&lt;&lt;diff(time1,time2).tv_nsec&lt;&lt;endl; return 0; } timespec diff(timespec start, timespec end) { timespec temp; if ((end.tv_nsec-start.tv_nsec)&lt;0) { temp.tv_sec = end.tv_sec-start.tv_sec-1; temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; } else { temp.tv_sec = end.tv_sec-start.tv_sec; temp.tv_nsec = end.tv_nsec-start.tv_nsec; } return temp; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload