dmilicev

program_execution_time_v1.c

Aug 16th, 2020
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     program_execution_time_v1.c
  4.  
  5.     https://www.tutorialspoint.com/c_standard_library/c_function_clock.htm
  6.  
  7.  
  8.     You can find all my C programs at Dragan Milicev's pastebin:
  9.  
  10.     https://pastebin.com/u/dmilicev
  11.  
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <time.h>           // clock_t, clock(), CLOCKS_PER_SEC
  16.  
  17. int main (void)
  18. {
  19.     clock_t start_time, end_time;
  20.     double elapsed_time;
  21.     int i;
  22.  
  23.     start_time = clock();   // start measuring time
  24.  
  25.     for(i=0; i< 1000; i++)  // a function whose execution time is measured
  26.     {
  27.         printf("\n i = %d", i);
  28.     }
  29.  
  30.     end_time = clock();     // end measuring time
  31.  
  32.     elapsed_time = (double)(end_time - start_time) / CLOCKS_PER_SEC;
  33.  
  34.     printf("\n\n CLOCKS_PER_SEC = %d \n", CLOCKS_PER_SEC);
  35.  
  36.     printf("\n start_time   = %5ld clocks \n end_time     = %5ld clocks \n\n elapsed_time = %lf s \n",
  37.             start_time, end_time, elapsed_time);
  38.  
  39.     return(0);
  40. }
  41.  
RAW Paste Data Copied