title: Measuring time taken by a function: clock_gettime
body: <p>I am trying to measure how long a function takes.</p>
  <p>I have a little issue: although I am trying to be precise, and use floating points, every time I print my code using <code>%lf</code> I get one of two answers: <code>1.000</code>... or <code>0.000</code>... This leads me to wonder if my code is correct:</p>
  <pre><code>#define BILLION  1000000000L;
  
  // Calculate time taken by a request
  struct timespec requestStart, requestEnd;
  clock_gettime(CLOCK_REALTIME, &amp;requestStart);
  function_call();
  clock_gettime(CLOCK_REALTIME, &amp;requestEnd);
  
  // Calculate time it took
  double accum = ( requestEnd.tv_sec - requestStart.tv_sec )
    + ( requestEnd.tv_nsec - requestStart.tv_nsec )
    / BILLION;
  printf( &quot;%lf\n&quot;, accum );
  </code></pre>
  <p>Most of this code has not been made by me. This example page had code illustrating the use of <a href="http://www.users.pjwstk.edu.pl/%7Ejms/qnx/help/watcom/clibref/qnx/clock_gettime.html" rel="nofollow noreferrer"><code>clock_gettime</code></a>:</p>
  <p>Could anyone please let me know what is incorrect, or why I am only getting <code>int</code> values please?</p>