C Program To Calculate Execution Time of a Program
Learn How To Find Execution Time of a Program in C Programming Language. This C Program makes use of the time.h header file which has definitions for clock() method.
In order to calculate the time taken by a C program to complete its execution, the library function clock_t clock(void) returns the clock ticks elapsed since the program started its execution. The clock() can be invoked at the beginning of the C program with start value and a finish value can be invoked at the end of the C program. The final running time can be calculated by subtracting the start and finish values.
C Program To Find Execution Time of a Program using Time.h Header File
clock_t starting_time, finishing_time;
int i, j;
starting_time = clock();
finishing_time = clock();
printf("\nStarting Time:\t%ld", starting_time);
printf("\nEnding Time:\t%ld", finishing_time);
printf("\nTotal Time For Execution:\t%ld\n", finishing_time - starting_time);
If you have any compilation errors or doubts in this C Program To Find Running Time of a Program in Milliseconds, let us know about it in the comment section below.