设定CPU主频

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值