取得CPU速度的代碼
class CCPUCalcutor
{
unsigned __int64 m_start;
public:
unsigned __int64 m_overhead;
CCPUCalcutor(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;
}
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
}
DWORD GetCPUSpeed()
{
Start();
Sleep(100);
unsigned cpuspeed100 = (unsigned)(Stop()/1000);
return cpuspeed100/100;
}
};CCPUCalcutor cpuCalc;
cpuCalc.GetCPUSpeed();
posted on 2007-05-15 16:02 笨笨 閱讀(1899) 評論(2) 編輯 收藏 引用 所屬分類: Windows編程

