#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;
}

相关文章:

  • 2022-12-23
  • 2022-02-24
  • 2021-12-04
  • 2022-12-23
  • 2021-08-31
  • 2021-12-14
  • 2021-11-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案