The Code Project Codejock Software - Serious GUI Code
Home >> System >> General

Whats my CPU Speed?
By Colin Davies

Some simple functions for system stats 
 VC6, Win95, Win98, NT4, MFC
 Posted 29 Jun 2000
Articles by this author
Send to a friend
Printer friendly version
Home Lounge New Articles Logon Forums Contribute
Broken links? Email us!
18 users have rated this article. result:
4.39 out of 5.

  • Download demo project - 34 Kb
  • Sample Image - SysInfox.jpg
    As you can see I should upgrade my PC :-)

    CPU Speed and other stuff

    Recently I had a small games developer ask me to develop some functions for determining some windows platform statistics of the Users. So really this project was going to be modified to being a DLL, but it never got to that stage. And thus was never used and I'm posting it here instead :-)

    CPU Speed

    I discovered this to be a fascinating topic being a non HardWare guy, And learn't a lot of irrelevant stuff in the process

    1. Intel supplies a cpuinf32.dll to recover the CPU speed from a time stamp, (However this fails on overclocked PC's and illegal cloned CPU's)
    2. There are a host of methods for calculating the CPU speed.
    3. CPU speeds vary greatly with temperature and voltage differences.

    However the method I finally used to get the CPU speed was quite simplistic,

    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;
        }
    };
    

    and

    void CSysInfoDlg::OnButtonRawclockfrequency() 
    {
    	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  );
    	m_RawClockFrequencyControl.SetWindowText(strRawClockFrequency);
    }
    

    The other stuff?

    The other stuff is for getting the window size settings and the amount of RAM available, I'm unsure if the RAM functions are indeed acurate, But hey they return a value, :-)

    Anyhow...

    Good luck to anyone who finds a use for this code.

    About Colin Davies

    NZ based independant developer

    [Top] Rate this Article for us!     PoorExcellent  
    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 10 of 10 (Total: 10)First Prev Next Last
    Subject 
    Author 
    Date 
      how to get Video Memory size???
    d2724 21:34 30 Oct 00 
      "brand" i.e. celeron detection
    Mark Hutton 19:01 15 Aug 00 
      Re:
    Mark Hutton 20:31 15 Aug 00 
      Re:
    Mark Hutton 21:01 15 Aug 00 
      "brand" i.e. celeron detection
    Mark Hutton 19:01 15 Aug 00 
      vendor id
    mark 18:53 14 Aug 00 
      Problem with an old Cyrix processor
    Jeremy Davis 11:54 3 Jul 00 
      Re: Problem with an old Cyrix processor
    Colin Davies 19:27 3 Jul 00 
      Re: Problem with an old Cyrix processor
    Jeremy Davis 4:27 4 Jul 00 
      Can't even....
    mark 1:31 30 Jun 00 
    Last Visit: 12:00 Friday 1st January, 1999First Prev Next Last

    Home >> System >> General
    last updated 29 Jun 2000
    Article content copyright Colin Davies, 2000
    everthing else © CodeProject, 1999-2001.
    The Code Project Click here for Whole Tomato Software - Home of Visual Assist