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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include<stdio.h> #include<time.h> int main() { clock_t starting_time, finishing_time; int i, j; starting_time = clock(); finishing_time = clock(); printf("\nStarting Time:\t%ld", starting_time); printf("\nHello World"); printf("\nEnding Time:\t%ld", finishing_time); printf("\nTotal Time For Execution:\t%ld\n", finishing_time - starting_time); return 0; } |
Output

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.
OMG! This is fantastic. Now, I don’t need to go to an online compiler to measure the running time of my C program. Thanks a lot CodingAlpha.
it is not working in turbo c++
Please check if Turbo C supports time.h.