Http://community.csdn.net/Expert/FAQ/FAQ_Index.asp? Id = 211457
How accurate do you need?
Gettickcount can be 18-20 ms
Timegettime can reach 1 ms precision
......
Of course, these are not supported by the C or C ++ standard.
Then we will sacrifice the best way,
Reads the number of machine cycles executed since the CPU is started,
An assembly command: rdtsc (read timestamp count)
The precision can reach the NS level. (Accurately speaking, the precision is 1/the clock frequency of your CPU, which is also the limit)
Long highstart, lowstart, highend, lowend;
Long numhigh, numlow;
_ ASM
{
Rdtsc
MoV highstart, EDX
MoV lowstart, eax
// Put your time-consuming code here ......
Rdtsc
MoV highend, EDX
MoV lowend, eax
// Obtain the counter value difference twice
Sub eax, lowstart
CMP eax, 0
JG L1
Neg eax
JMP L2
L1: mov numlow, eax
L2: SBB edX, highstart
MoV numhigh, EDX
}
_ Int64 timer = (numhigh <32) + numlow; // get the final result