title: Easily measure elapsed time
body: <p>I am trying to use <a href="http://en.cppreference.com/w/cpp/chrono/c/time" rel="noreferrer">time()</a> to measure various points of my program.</p>
  
  <p>What I don't understand is why the values in the before and after are the same?  I understand this is not the best way to profile my program, I just want to see how long something take.  </p>
  
  <pre><code>printf("**MyProgram::before time= %ld\n", time(NULL));
  
  doSomthing();
  doSomthingLong();
  
  printf("**MyProgram::after time= %ld\n", time(NULL));
  </code></pre>
  
  <p>I have tried:</p>
  
  <pre><code>struct timeval diff, startTV, endTV;
  
  gettimeofday(&amp;startTV, NULL); 
  
  doSomething();
  doSomethingLong();
  
  gettimeofday(&amp;endTV, NULL); 
  
  timersub(&amp;endTV, &amp;startTV, &amp;diff);
  
  printf("**time taken = %ld %ld\n", diff.tv_sec, diff.tv_usec);
  </code></pre>
  
  <p>How do I read a result of <code>**time taken = 0 26339</code>?  Does that mean 26,339 nanoseconds = 26.3 msec?</p>
  
  <p>What about <code>**time taken = 4 45025</code>, does that mean 4 seconds and 25 msec?</p>