Windows 毫秒计时
#include <windows.h>
#include <iostream>
using namespace std;
LARGE_INTEGER MilliSecondTimeStamp()
{
LARGE_INTEGER m_liPerfStart = { 0 };
QueryPerformanceCounter(&m_liPerfStart);
return m_liPerfStart;
}
long long MilliSecondTimeCost(LARGE_INTEGER begin, LARGE_INTEGER end)
{
LARGE_INTEGER m_liPerfFreq = { 0 };
//获取每秒多少CPU Performance Tick
QueryPerformanceFrequency(&m_liPerfFreq);
return ((end.QuadPart - begin.QuadPart) * 1000) / m_liPerfFreq.QuadPart;
}
int main(void)
{
LARGE_INTEGER begin = MilliSecondTimeStamp();
for (int i = 0; i < 10000; i++)
cout << i << endl;
LARGE_INTEGER end = MilliSecondTimeStamp();
long long time = MilliSecondTimeCost(begin, end);
cout << endl << "execute cost " << time << "ms" << endl;
//int time=( ((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000)/m_liPerfFreq.QuadPart);
//char buffer[100];
//sprintf(buffer, "execute cost%d millisecond ", time);
//cout << buffer << endl;
return 0;
}
转载本Blog文章请注明出处,否则,本作者保留追究其法律责任的权利。
本人转载别人或者copy别人的博客内容的部分,会尽量附上原文出处,仅供学习交流之用,如有侵权,联系立删。