Tuesday, 13 May 2014

How to find the frequency of processor on WinXP

The header file #include is used in windows platform
Declare the variable freq of type large 
 LARGE_INTEGER freq;

call the function
QueryPerformanceFrequency(&freq);

print the value of freq

This will get you the frequency of you CPU

Code:
#include
#include
#include
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  cout << "The resolution of this timer is: " << freq.QuadPart << " Hz." <  getch();
}

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.