获得CPU速度的Delphi 函数

这个有意思,虽然是个老程序了,对于3Ghz的CPU算的还是很准的envy


function TscSystemInfo.GetCPUSpeed : Double;
const
IntDelayTime = 500; // time in ms
var
TimerHi, TimerLo: DWORD;
IntPriorityClass, IntPriority: Integer;
begin
IntPriorityClass := GetPriorityClass(GetCurrentProcess);
IntPriority := GetThreadPriority(GetCurrentThread);

SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

Sleep(10);
asm
dw 310Fh
mov TimerLo, eax
mov TimerHi, edx
end;
Sleep(IntDelayTime);
asm
dw 310Fh
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
end;

SetThreadPriority(GetCurrentThread, IntPriority);
SetPriorityClass(GetCurrentProcess, IntPriorityClass);

Result := TimerLo / (1000.0 * IntDelayTime);
end;