CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Location
    UK
    Posts
    4

    Unhappy Timer & CpuID......pls help

    Hi all


    I'm trying to work out how to return an estimation of processor speed, but without luck. Under Windows NT/2000/XP I can simply read the corresponding keys of the registry, but I would like an alternative way of doing it.

    I've played around with various API's, but with no success.

    I'm currently trying to get it to work using the high-performance counters to measure the specific time taken to perform a given calculation, but at the moment it returns the same results on a Pentium II 266 as it does on an Athlon Tbird 1GHz, so there's obviously something going wrong somewhere. Could you please tell me if I'm going about it the right way with my code below (am I using the QueryPerformance functions properly?): -



    ' ============= MY CODE : ================

    Type LARGE_INTEGER
    lowpart As Long
    highpart As Long
    End Type
    ' CUSTOM DATA TYPE TO HANDLE LARGE INTEGERS



    Declare Function QueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (lpFrequency As LARGE_INTEGER) As Long
    Declare Function QueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As LARGE_INTEGER) As Long
    ' I DECLARE THE API FUNCTIONS HERE

    dim constFreq as LARGE_INTEGER
    dim time1 as LARGE_INTEGER
    dim time2 as LARGE_INTEGER
    dim outTime as Double
    dim timeDif as Long
    ' VARIABLE DECLERATIONS



    QueryPerformanceCounter(lpPerformanceCount)
    lpPerformanceCount = time1
    ' QUERY OF PERFORMANCE COUNTER BEFORE THE EQUATION

    ' MY CALCULATIONS TO TIME GOES HERE

    QueryPerformanceCounter(lpPerformanceCount)
    lpPerformanceCount = time2
    ' QUERY OF PERFORMANCE COUNTER AFTER THE EQUATION

    QueryPerformanceFrequency(lpFrequency)
    lpFrequency = constFreq
    ' QUERY THE PERFORMANCE FREQUENCY (CONSTANT - CPU SPECIFIC)



    timeDif = time2-time1
    outTime = timeFif/constFreq
    ' CALCULATE PERFORMANCE RATIO

    ' I OUTPUT THE RESULTS HERE

    ' =========== END OF CODE =============



    Also, is the CpuID source code as provided by Intel & AMD freely distributable, and how do I make use of it simply to detect CPU speed?

    I'm quite new to VB, so really I need just some simple to understand code that will make a rough estimation of CPU speed.


    Any help would be very much apreciated.
    All the very best,


    Gav

  2. #2
    Join Date
    May 2002
    Location
    UK/Northanptonshire
    Posts
    45

    Lightbulb Code

    I can't help with the timers try looking at the INTEL web site.... or ask there support team about it..

    now the CPU ID i can do..


    bool CMyClass::HasCpuSeiralNumber()
    {
    #if _DEBUG
    return true;
    #else
    DWORD Flag=0l;
    DWORD Test=0x20000;
    __asm
    {
    MOV EAX,01H
    CPUID
    MOV Flag,EDX
    }
    if((Flag & Test)==Test) // CPUID Supported
    return true;
    return false;
    #endif
    }

    CString CMyClass::GetCpuSeiralNumber()
    {
    DWORD _Hi,_Mid,_Low;
    _Hi=_Mid=_Low=0x0;

    __asm
    {
    MOV EAX, 01H
    CPUID
    MOV _Hi, EAX
    MOV EAX, 03H
    CPUID
    MOV _Low, ECX
    MOV _Mid, EDX

    }

    DWORD H1,H2,M1,M2,L1,L2;
    H1=H2=M1=M2=L1=L2=0x0;

    H1=HIWORD(_Hi);
    H2=LOWORD(_Hi);
    M1=HIWORD(_Mid);
    M2=LOWORD(_Mid);
    L1=HIWORD(_Low);
    L2=LOWORD(_Low);

    CString Temp;
    Temp.Format("%04X-%04X-%04X-%04X-%04X-%04X",H1,H2,M1,M2,L1,L2);
    return Temp;
    }

    Have fun

    Tony
    Programming better that Sex? Well dose depend on who with!!
    If you found this item to be useful please rate it.....

  3. #3
    Join Date
    May 2002
    Location
    UK
    Posts
    4

    Smile

    Thanks Tony


    Looks a bit complicated to me right now.
    Will have a go with it & post results.
    Cheers.
    All the very best,


    Gav

  4. #4
    Join Date
    May 2002
    Location
    UK/Northanptonshire
    Posts
    45

    Wink How To use it

    in your code do the following.

    // Test for CPU ID

    if(myclass.HasCpuSeiralNumber()==true)
    {
    AfxMessageBox(myclass.GetCpuSeiralNumber());
    }
    else
    {
    AfxMessageBox("CPU Dose Not Have a ID Number");
    }

    you can get a test program from www.intel.com so you can see the CPUID number.
    Programming better that Sex? Well dose depend on who with!!
    If you found this item to be useful please rate it.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured