Here i shared a simple method to calculate program execute time or time elapsed in C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*calculate program execute time */
#include <time.h>
#include <stdio.h>
 
int main(int argc, char *argv[]) {
   time_t start, stop;
   clock_t ticks; long count;
 
   time(&start);
   // Do stuff
   int i=0;
 
   while(i<50000)
   {
	printf("Work work %d\n", i);
        i++;
        ticks = clock();
 
   }
 
   time(&stop);
 
   printf("Used %0.2f seconds of CPU time. \n", (double)ticks/CLOCKS_PER_SEC);
   printf("Finished in about %.0f seconds. \n", difftime(stop, start));
   return 0;
}