Find Execution time of your own Program

#include<stdio.h>
#include<time.h>

/*
The C library function clock_t clock(void) returns the number
of clock ticks elapsed since the program was launched.
To get the number of seconds used by the CPU, you will
need to divide by CLOCKS_PER_SEC.

*/


int main() {
clock_t start, end;
double total;
int i,j;
start = clock();
int c;
for (i = 0; i < 100; i++) {
for (j = 0; j < 100; j++) {
c++;
}
}

end = clock();
printf("start = %d, end = %d\n", start, end);
printf("\nTotal = %ld",end-start);

return 0;
}

Leave a comment