1. The return unit is milliseconds.
# Include <windows. h>
DWORD dwstart = gettickcount ();
// TestCode
DWORD dwtime = gettickcount ()-dwstart;
2. Return time is second
# Include <time. h>
Unsigned long start, stop;
Start = Time (null); // The value is second.
// YourProgram
Stop = Time (null );
Printf ("running time: % lD", stop-start );
Iii. Exact timing method
Queryperformancecounter () This function returns the value of the high-precision performance counter, which can be in subtle units
Timing. However, the minimum unit of the exact timing of queryperformancecounter () is related to the system. Therefore
You must check the frequency of the response from queryperformancecounter () to the query system.
Rate. queryperformancefrequency () provides this frequency value and returns the number of clicks per second.
The period starts when queryperformancecounter () is called for the first time.
Use the APIS provided by the window operating system. The procedure is as follows:
# Include <windows. h>
Large_integer freq; large_integer start; large_integer end;
Queryperformancefrequency (& freq); // get the clock cycle
Queryperformancecounter (& START); // get the clock count
Your program
Queryperformancecounter (& End );
/* Here * 1000, in milliseconds; * 1000000 in microseconds */
/* Because the execution time is very short (may be several microseconds), the Unit is microseconds */
Printf ("% d", (end. QuadPart-start.QuadPart) * 1000000/freq. quadpart );