|
-
Jul 2nd, 2001, 04:30 AM
#1
Thread Starter
Lively Member
Measuring cpu speed
Can someone tell me if there is an api call that returns the cpu speed and what it is? thx.
-
Jul 2nd, 2001, 06:21 AM
#2
Declare Function GetTickCount Lib "Kernel32" Alias "GetTickCount" () as Long
Is the simple way to do it, returns number of millisec since the OS booted.
-
Jul 2nd, 2001, 06:30 AM
#3
Thread Starter
Lively Member
Not sure how knowing how long the current windows session has been running in milliseconds helps me get the MHtz speed of the cpu?
-
Jul 2nd, 2001, 08:10 AM
#4
-
Jul 2nd, 2001, 09:32 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|