求救,如何在DELPHI中测CPU的类型和频率(100分)

  • 主题发起人 主题发起人 chentf
  • 开始时间 开始时间
C

chentf

Unregistered / Unconfirmed
GUEST, unregistred user!
在VC中用以下代码可以测出CPU的主频:
static int time[2]
int cpuclock;
在InitInstance中
SetTimer(hWnd,1,1000,NULL)
在消息处理过程中
case WM_CREATE;
_asm{
rdtsc //一个64bit的时间标记计数器
mov ecx,offset time
mov [ecx+0],edx
mov [ecx+4],eax
}
break;
case WM_TIMER:
_asm
{
rdtsc
mov ebx,offset time
sub eax,[ebx+4]
sbb edx,[ebx+0]
mov ecx,1000000
div ecx
mov cpuclock,eax
}
但不知在DELPHI中如何编程测试?还有CPU的类型等等!
 
SetTimer(handle,1,1000,NULL);
...
...(var msg: message)...
if msg.message=WM_CREATE then
begin
asm
rdtsc //一个64bit的时间标记计数器
mov ecx,offset time
mov [ecx+0],edx
mov [ecx+4],eax
end;
end;
if msg.message=WM_TIMER then
begin
asm
rdtsc
mov ebx,offset time
sub eax,[ebx+4]
sbb edx,[ebx+0]
mov ecx,1000000
div ecx
mov cpuclock,eax
end;
end;
 
function GetCPUSpeed:do
uble;
const
DelayTime = 500;
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
try
PriorityClass := GetPriorityClass(GetCurrentProcess);
Priority := GetThreadPriority(GetCurrentThread);
SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread,THREAD_PRIORITY_TIME_CRITICAL);
Sleep(10);
asm
dw 310Fh // rdtsc
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(DelayTime);
asm
dw 310Fh // rdtsc
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;
SetThreadPriority(GetCurrentThread, Priority);
SetPriorityClass(GetCurrentProcess, PriorityClass);
Result := TimerLo / (1000.0 * DelayTime);
except
Result := 0;
end;
end;
 
Reboot,thank you very much.
 
哎,实在是太长了,发个email给你吧。
 
接受答案了.
 
后退
顶部