Can someone tell me if there is an api call that returns the cpu speed and what it is? thx.
Printable View
Can someone tell me if there is an api call that returns the cpu speed and what it is? thx.
Declare Function GetTickCount Lib "Kernel32" Alias "GetTickCount" () as Long
Is the simple way to do it, returns number of millisec since the OS booted.
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:
Try this thread.
http://www.vbforums.com/showthread.p...ight=cpu+speed
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)