| // CPUSpeedDlg.cpp : implementation file // #include "stdafx.h" #include "CPUSpeed.h" #include "CPUSpeedDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /////////////////////////////////////////////// // CAboutDlg dialog used for App About inline unsigned __int64 theCycleCount(void) { _asm _emit 0x0F _asm _emit 0x31 /// this causes a compiler warning as there is no return statement /// however the _emits return a __int64 value } class CTimer { unsigned __int64 m_start; public: unsigned __int64 m_overhead; CTimer(void) { m_overhead = 0; Start(); /// we get the start cycle m_overhead = Stop(); // then we get the stop cycle catching the overhead time } void Start(void) { m_start = theCycleCount(); } unsigned __int64 Stop(void) { /// with the stop cycle we remove the overhead's time return theCycleCount()-m_start-m_overhead; } }; void CCPUSpeedDlg::OnButton1() { // TODO: Add your control notification handler code here CString strRawClockFrequency; CTimer timer; long tickslong; long tickslongextra; timer.Start(); Sleep(1000); unsigned cpuspeed100 = (unsigned)(timer.Stop()/10000); tickslong = cpuspeed100/100; tickslongextra = cpuspeed100-(tickslong*100); strRawClockFrequency.Format("%d.%d MHZ estimate ", tickslong,tickslongextra ); AfxMessageBox("CPU速度为"+strRawClockFrequency); } class CAboutDlg : public CDialog { ……以下为编程环境生成时自动生成的代码。 |
关注此文的读者还看过: