Author: Ed Schröder
Date: 14:45:34 01/14/04
Go up one level in this thread
On January 14, 2004 at 16:58:49, martin fierz wrote:
>darn, hit tab and return :-)
>
>again:
>i'm looking for a way to determine the clock speed of a CPU with MSVC. i found
>some stuff on CPUID on the net; some _asm routines which return strings like
>"AuthenticAMD" or "GenuineIntel", and processor model numbers, stepping numbers
>etc. but that's not what i'm really looking for. i dream of the following
>function:
>
>int cpuid(char *s)
>
>which i could call from my C program and which would return something like this:
>
>Intel Pentium III at 866MHz
>
>or
>
>AMD Athlon at 1400MHz
>
>etc.
>
>it looks like arena for instance can do this. did anybody ever write such a
>C-callable function and is willing to share it?
>
>cheers
> martin
Martin, I once found the below on the Internet, it is not accurate but does a
pretty good job.
My best,
Ed
=======================
GetCpuSpeed()
{
int timeStart = 0;
int timeStop = 0;
unsigned long StartTicks = 0;
unsigned long EndTicks = 0;
unsigned long TotalTicks = 0;
unsigned long cpuSpeed = 0;
timeStart = clock(); // Get tick edge
for( ; ; )
{ timeStop = clock();
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
}
break;
}
}
timeStart = timeStop;
for( ; ; )
{ timeStop = clock();
if ( (timeStop-timeStart) > 1000 ) // one second
{
asm { xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
_emit 0x0f
_emit 0xa2
_emit 0x0f
_emit 0x31
mov [EndTicks], eax }
break;
}
}
TotalTicks = EndTicks-StartTicks; // total
cpuSpeed = TotalTicks/1000000; // speed
return(cpuSpeed);
}
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.