title: Calculation time elapsed by a particular function in C program
body: <p>I have a code in which i want to calculate the time taken by two sorting algorithms merge sort and quick sort to sort N numbers in microseconds or more precise.
  The two times thus calculated will then we outputted to the terminal.
  Code(part of code):</p>
  
  <pre><code>printf("THE LIST BEFORE SORTING IS(UNSORTED LIST):\n");
  printlist(arr,n);
  mergesort(extarr,0,n-1);
  printf("THE LIST AFTER SORTING BY MERGE SORT IS(SORTED LIST):\n");
  printlist(extarr,n);
  quicksort(arr,0,n-1);
  printf("THE LIST AFTER SORTING BY QUICK SORT IS(SORTED LIST):\n");
  printlist(arr,n);
  </code></pre>
  
  <p>Help me by providing that how it will be done.I have tried clock_t by taking two variables as start stop and keeping them above and below the function call respectively but this doesnt help at all and always print out the its difference as zero.
  Please suggest some other methods or function keeping in mind that it has no problem running in any type of OS.
  Thanks for any help in advance.</p>