Let us 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 the 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 Calculate 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.