Saturday, 10 May 2014

How to calculate the Execution time of a program

For calculating the time in C language we can use the header file time.h

The time.h header file contains a macro name called CLK_TCK.

It has been made obsolete in some of compiler.

This variable provides the number of clock ticks per second.

The default value in many compiler of this macros is 18.2

Now to record the number clock tick between two events we can use the declaration like

clock_t  start,end;

here start and end are the variables.

start is used to begining tick value

end is used to strore ending tick value.

 that is by calling start= clock();

and end=clock();

now elapsed time in second will be given by the formula

(end -start)/CLK_TCK

The time calculated by this functions will be in seconds.

and the accuracy of this functions is for  1/18.2 seconds and it can't record the events which are completed 
in time less than this.

No comments:

Post a Comment