C++高精度计算代码运行时间

	//在定时前应该先调用QueryPerformanceFrequency()函数获得机器内部计时器的时钟频率.
	//接着在需要严格计时的事件发生前和发生之后分别调用QueryPerformanceCounter(),利用两次获得的计数之差和时钟频率,就可以计算出事件经历的精确时间,
	//供WIN9X使用的高精度定时器:QueryPerformanceFrequency()和QueryPerformanceCounter(),要求计算机从硬件上支持高精度定时器.
	//数据类型LARGEINTEGER既可以是一个作为8字节长的整数,也可以是作为两个4字节长的整数的联合结构,其具体用法根据编译器是否支持64位而定.
	LARGE_INTEGER Frequency = {0};
	QueryPerformanceFrequency(&Frequency);
	double F    = (double)Frequency.QuadPart;
	QueryPerformanceCounter(&Frequency);
	LONGLONG I  = Frequency.QuadPart;
	{
		//do sth here
	}
	QueryPerformanceCounter(&Frequency);
	string result;
	result.Format(_T("Result: %f"), double(Frequency.QuadPart - I) / F);
	MessageBox(NULL, p, _T("测试报告"), MB_OK);


你可能感兴趣的:(C/C++,c++,integer,编译器,string,null,测试)