Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- program_execution_time_v1.c
- https://www.tutorialspoint.com/c_standard_library/c_function_clock.htm
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #include <time.h> // clock_t, clock(), CLOCKS_PER_SEC
- int main (void)
- {
- clock_t start_time, end_time;
- double elapsed_time;
- int i;
- start_time = clock(); // start measuring time
- for(i=0; i< 1000; i++) // a function whose execution time is measured
- {
- printf("\n i = %d", i);
- }
- end_time = clock(); // end measuring time
- elapsed_time = (double)(end_time - start_time) / CLOCKS_PER_SEC;
- printf("\n\n CLOCKS_PER_SEC = %d \n", CLOCKS_PER_SEC);
- printf("\n start_time = %5ld clocks \n end_time = %5ld clocks \n\n elapsed_time = %lf s \n",
- start_time, end_time, elapsed_time);
- return(0);
- }
RAW Paste Data
Copied