#define STRICT
#include
#include
#include
inline unsigned __int64 GetCycleCount(void)
{
_asm _emit 0x0F
_asm _emit 0x31
}
class KTimer
{
public:
unsigned __int64 m_startcycle;
unsigned __int64 m_overhead;
KTimer(void)
{
m_overhead = 0;
//Start();
//m_overhead = Stop();
m_startcycle = GetCycleCount();
m_overhead = GetCycleCount() - m_startcycle - m_overhead; // m_overhead 是调用GetCycleCount()占用的时间
}
void Start(void)
{
m_startcycle = GetCycleCount();
}
unsigned __int64 Stop(void)
{
return GetCycleCount() - m_startcycle - m_overhead;
}
};
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmd,
int nShow)
{
KTimer timer;
TCHAR mess[128];
timer.Start();
Sleep(1000);
unsigned cpuspeed10 = (unsigned)(timer.Stop()/100000);
/*
timer.Start();
CreateSolidBrush(RGB(0xAA, 0xAA, 0xAA));
unsigned time = (unsigned)timer.Stop();
*/
wsprintf(mess, _T("CPU speed %d.%d Ghz"), cpuspeed10 / 10000000000, cpuspeed10 % 1000000000);
wsprintf(mess, _T("CPU speed %d.%d Ghz"), cpuspeed10 / 10000, cpuspeed10 % 10000);
/*
wsprintf(mess, _T("CPU speed %d.%d mhz/nKTimer overhead %d clock cycles/nCreateSolidBrush %d clock cycles %d ns"),
cpuspeed10 / 10, cpuspeed10 % 10,
(unsigned)timer.m_overhead,
time, time * 1000 / cpuspeed10);
*/
MessageBox(NULL, mess, _T("How fast is GDI?"), MB_OK);
return 0;
}
参考:http://topic.youkuaiyun.com/t/20021211/17/1252115.html
设定CPU主频
最新推荐文章于 2023-05-07 17:05:38 发布
3697

被折叠的 条评论
为什么被折叠?



