Sunday, September 1, 2013

How to find execution time of program in C??

We always eager to know that how much time my program takes to give me output. As a good programmer you always worry about the time complexity. If you print your execution time along with output then you can check your execution time for different test cases. It's really exiting.


#include<stdio.h>
#include<time.h>
int main()
{
clock_t begin, end;
begin = clock();
double time_spent;

/*
     write your code
*/

end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("\n execution time for sorting: %f seconds ",time_spent);

return 0;

}

0 comments:

Post a Comment