How to calculate program execution time in C?

+1 vote
How to calculate program execution time in C?
closed with the note: Got the answer
asked May 16, 2012 in Data Structures and Algorithms by CareerMonk (17,460 points)
closed May 16, 2012 by CareerMonk
  

1 Answer

0 votes
 
Best answer

/*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));
   system("PAUSE");
   return 0;
}
answered May 16, 2012 by CareerMonk (17,460 points)

Related questions

+3 votes
1 answer
118 views asked Aug 1, 2012 in C/C++ by amit58 (150 points)
+1 vote
1 answer
0 votes
1 answer
+1 vote
2 answers
+2 votes
1 answer