c++ 程序计时

#include<time.h>

LARGE_INTEGER timeStart;  
LARGE_INTEGER timeEnd;    
LARGE_INTEGER frequency;
double        quadpart;
 
QueryPerformanceFrequency(&frequency);
quadpart = (double)frequency.QuadPart;
QueryPerformanceCounter(&timeStart);


xxxxxxx   // the function been tested


QueryPerformanceCounter(&timeEnd);
int32_t  time  = 1000 * (timeEnd.QuadPart - timeStart.QuadPart) / quadpart; // ms

ofstream outfile("d://testRunTime.txt", ios::app);
if (outfile.is_open())
{
    outfile<<"run time is "<<time<<endl;
}
outfile.close();

猜你喜欢

转载自blog.csdn.net/myzhouwang/article/details/83861000