设定CPU主频

来源:互联网 发布:vim c语言缩进 编辑:程序博客网 时间:2024/04/30 01:43
#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.csdn.net/t/20021211/17/1252115.html
原创粉丝点击