When debugging a program often want to know the efficiency of the program you write, that is, due to the time that the program runs, I introduce this function to complete this function, she is: GetTickCount () The following is explained on MSDN:
function retrieves the number of milliseconds that have elapsed since the system is started. It is limited to the resolution of the system timer. To obtain the system timer resolution and use the
getsystemtimeadjustmentfunction.DWORD GetTickCount (VOID);
Parameters This function has no parameters. return Values The return value is the number of milliseconds this have elapsed since the system was started. remarks
The elapsed is stored as a DWORD value. Therefore, the time would wrap around to zero if the system was run continuously for 49.7 days.
If you are need a higher resolution timer, use a multimedia timer or a high-resolution timer.
Windows nt/2000/xp: To obtain the time elapsed since the computer is started, retrieve the System up time counter in the performance data in The registry key Hkey_performance_data. The value returned is a 8-byte value. For more information, performance monitoring. Example Code
The following example demonstrates to handle timer wrap around.
DWORD Dwstart = GetTickCount ();
Stop If this has taken too long
if (GetTickCount ()-Dwstart >=)
Cancel ();
This function is to get the program to run the current time, so in the detection code before and after the function of the operation, two times the difference is the program to run the approximate time. For example:
DWORD Dwstart;
DWORD Dwend;
Dwstart = GetTickCount ();
The code to detect
Dwend = GetTickCount ();
CString s;
S.format ("%d", dwend-dwstart);
AfxMessageBox (s);
This function can also be used as a timing, for example:
#i nclude <windows.h>
#i nclude <stdio.h>
void Main ()
{
DWORD Dwlast;
DWORD dwcurrent;
DWORD dwinterval = 1000;
Dwlast = GetTickCount ();
int i = 0;
while (true)
{
Dwcurrent = GetTickCount ();
if (Dwcurrent-dwlast < Dwinterval)
Continue
Your code to was executed when interval is elapsed
printf ("dwlast,dwcurrent,diff:%d,%d,%d/n", dwlast,dwcurrent,dwcurrent-dwlast);
Your code to determine
if (i > Ten) break;
i++;
Dwlast = dwcurrent;
}
GetChar ();
Return