title: the use of getitimer and setitimer in C
body: <p>I am writing the following C code to get the time taken to perform a simple operation using getitimer and setitimer.</p>
  
  <pre><code>#include &lt;sys/time.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;limits.h&gt;
  #include &lt;string.h&gt;
  
  #define INTERVAL 1        /* number of milliseconds to go off */
  
  int main() {
      double sum = 0;
      struct itimerval initial, updated;
  
      initial.it_value.tv_sec     = INTERVAL;
      initial.it_value.tv_usec    = 999999;
      initial.it_interval = initial.it_value;
      memcpy(&amp;(initial.it_interval), &amp;(initial.it_value), sizeof( initial.it_value )); 
      printf("%ld\n", initial.it_value.tv_usec);
  
      if (setitimer(ITIMER_VIRTUAL, &amp;initial, NULL) == -1) {
          perror("error calling setitimer()");
          exit(1);
      }
  
      for (unsigned int i; i &lt; 100; i++) 
          sum += 1./i;
  
      if (getitimer(ITIMER_REAL, &amp;updated) == -1) {
          perror("error calling getitimer()");
          exit(1);
      }
  
      printf("Time started = %ld\n; Time ended = %ld\n: Time taken = %ld\n",
             initial.it_value.tv_usec, updated.it_value.tv_usec,
             initial.it_value.tv_usec - updated.it_value.tv_usec);
      return 0;
  }
  </code></pre>
  
  <p>I have compiled with:</p>
  
  <pre><code>$ gcc -o timer -std=c99 -Wall -pedantic getitimer.c -lrt -03
  </code></pre>
  
  <p>However, my answer is always 999999 (I have raised and decreased the 100):</p>
  
  <pre><code> ./timer 
  999999
  Time started = 999999
  ; Time endd = 0
  : Time taken = 999999
  </code></pre>
  
  <p>What is my error?  Also, I wanted to ask what is the highest precision I can get using a progrma like this? </p>
  
  <p>Thanks very much!</p>