Results 1 to 5 of 5

Thread: Measuring cpu speed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    *.*
    Posts
    85

    Measuring cpu speed

    Can someone tell me if there is an api call that returns the cpu speed and what it is? thx.

  2. #2
    evileconomist
    Guest
    Declare Function GetTickCount Lib "Kernel32" Alias "GetTickCount" () as Long

    Is the simple way to do it, returns number of millisec since the OS booted.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    *.*
    Posts
    85
    Not sure how knowing how long the current windows session has been running in milliseconds helps me get the MHtz speed of the cpu?


  4. #4
    jim mcnamara
    Guest

  5. #5
    evileconomist
    Guest
    I missunderstood the question, mhz speed ok!

    From GameDev forums I found the following C/C++ function
    (it's the same as in jim's link)

    uint32 GetCpuSpeed()
    {
    int timeStart = 0;
    int timeStop = 0;
    unsigned long StartTicks = 0;
    unsigned long EndTicks = 0;
    unsigned long TotalTicks = 0;
    unsigned long cpuSpeed = 0;


    timeStart = timeGetTime(); // Get tick edge
    for( ; ; )
    {
    timeStop = timeGetTime();
    if ( (timeStop-timeStart) > 1 ) // rollover past 1
    {
    __asm{
    xor eax, eax
    xor ebx, ebx
    xor ecx, ecx
    xor edx, edx
    _emit 0x0f // CPUID
    _emit 0xa2
    _emit 0x0f // RTDSC
    _emit 0x31
    mov [StartTicks], eax // Tick counter starts here
    }
    break;
    }
    }

    timeStart = timeStop;

    for( ; ; )
    {
    timeStop = timeGetTime();
    if ( (timeStop-timeStart) > 1000 ) // one second
    {
    __asm{
    xor eax, eax
    xor ebx, ebx
    xor ecx, ecx
    xor edx, edx
    _emit 0x0f // CPUID
    _emit 0xa2
    _emit 0x0f // RDTSC
    _emit 0x31
    mov [EndTicks], eax }
    break;
    }
    }

    TotalTicks = EndTicks-StartTicks; // total

    cpuSpeed = TotalTicks/1000000; // speed

    return((uint32)cpuSpeed);
    }



    It's possible this file comes from AMD's site (I haven't verfied)

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