代码只是演示下基本原理,未封装。
#include <windows.h>
#include <iostream>
int main()
{
DWORD m_lFreg;
LARGE_INTEGER timeFreq;
QueryPerformanceFrequency(&timeFreq);
m_lFreg = timeFreq.LowPart;
LARGE_INTEGER timeCount;
QueryPerformanceCounter(&timeCount);
double dBeginTime = (double)timeCount.QuadPart/(double)m_lFreg;
//
for(int i = 0; i < 99999999; i++)
{
float a = 123456789.f;
float b = 987654321.f;
float c = a*a/b/b;
}
//
QueryPerformanceCounter(&timeCount);
double dEndTime = (double)timeCount.QuadPart/(double)m_lFreg;
printf( "执行for循环所用时间为:%.10g秒\n",dEndTime-dBeginTime);
system("pause");
return 1;
}