Click to See Complete Forum and Search --> : Measuring cpu speed
Everytime
Jul 2nd, 2001, 04:30 AM
Can someone tell me if there is an api call that returns the cpu speed and what it is? thx.
evileconomist
Jul 2nd, 2001, 06:21 AM
Declare Function GetTickCount Lib "Kernel32" Alias "GetTickCount" () as Long
Is the simple way to do it, returns number of millisec since the OS booted.
Everytime
Jul 2nd, 2001, 06:30 AM
Not sure how knowing how long the current windows session has been running in milliseconds helps me get the MHtz speed of the cpu?
:confused:
jim mcnamara
Jul 2nd, 2001, 08:10 AM
Try this thread.
http://www.vbforums.com/showthread.php?s=&threadid=82385&highlight=cpu+speed
evileconomist
Jul 2nd, 2001, 09:32 AM
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)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.