title: How to get execution time of c program?
body: <p>I am using clock function for my c program to print execution time of current program.I am getting wrong time in output.I want to display time in seconds,milliseconds and microseconds.</p>
  
  <pre><code>#include &lt;stdio.h&gt; 
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt; 
  int main() 
  { 
      clock_t start = clock(); 
      sleep(3);
      clock_t end = clock(); 
      double time_taken = (double)(end - start)/CLOCKS_PER_SEC; // in seconds 
  
      printf("time program took %f seconds to execute \n", time_taken); 
      return 0; 
  } 
  
  
  time ./time
  time program took 0.081000 seconds to execute
  real    0m3.002s
  user    0m0.000s
  sys     0m0.002s
  </code></pre>
  
  <p>I expect output around 3 seconds however it display wrong.
  As you see <b>if I run this program using Linux command time</b> I am getting correct time,I want to display same time using my c program.</p>