1, millisecond level
- Use GetTickCount () to get the number of milliseconds that the system started
#include <iostream> usingnamespace std; int Main () { DWORD start// Gets the number of milliseconds to Sleep (+); <<:: GetTickCount ()-start<< Endl; System ("pause"); }
2. Use clock ()
#include <iostream><time.h><Windows.h>usingnamespace STD; int Main () { clock_t start; = clock (); Sleep (+); cout<<clock ()-start<<" ms"<<Endl; System ("pause");}
2, microsecond level
- Get the clock cycle first with QueryPerformanceFrequency () and call QueryPerformanceCounter () to get the number of clock cycles that the CPU has performed since it was powered on
#include <stdio.h>#include<math.h>#include<windows.h>using namespacestd;voidMain () {Large_integer cpuFreq; Large_integer StartTime; Large_integer EndTime; DoubleRumtime=0.0; QueryPerformanceFrequency (&cpuFreq); QueryPerformanceCounter (&startTime); Sleep ( +); QueryPerformanceCounter (&endTime); Rumtime= (((endtime.quadpart-starttime.quadpart) *1000.0f) /Cpufreq.quadpart); cout<< Rumttime <<"Ms"<<Endl;}
C + + Timers: Millisecond and microsecond levels