得到CPU速度,单位MHz
【打印文章】
function GetCpuSpeed: Comp;
{ function to return the CPU clock speed only.}
{ Usage: MessageDlg(Format('%.1f MHz', [GetCpuSpeed]),
mtConfirmation, [mbOk], 0); }
var
t: DWORD;
mhi, mlo, nhi, nlo: DWORD;
t0, t1, chi, clo, shr32: Comp;
begin
shr32 := 65536;
shr32 := shr32 * 65536;
t := GetTickCount;
while t = GetTickCount do begin end;
asm
DB 0FH
DB 031H
mov mhi,edx
mov mlo,eax
end;
while GetTickCount < (t + 1000) do begin end;
asm
DB 0FH
DB 031H
mov nhi,edx
mov nlo,eax
end;
chi := mhi;
if mhi < 0 then chi := chi + shr32;
clo := mlo;
if mlo < 0 then clo := clo + shr32;
t0 := chi * shr32 + clo;
chi := nhi;
if nhi < 0 then chi := chi + shr32;
clo := nlo;
if nlo < 0 then clo := clo + shr32;
t1 := chi * shr32 + clo;
Result := (t1 - t0) / 1E6;
end;
{ function to return the CPU clock speed only.}
{ Usage: MessageDlg(Format('%.1f MHz', [GetCpuSpeed]),
mtConfirmation, [mbOk], 0); }
var
t: DWORD;
mhi, mlo, nhi, nlo: DWORD;
t0, t1, chi, clo, shr32: Comp;
begin
shr32 := 65536;
shr32 := shr32 * 65536;
t := GetTickCount;
while t = GetTickCount do begin end;
asm
DB 0FH
DB 031H
mov mhi,edx
mov mlo,eax
end;
while GetTickCount < (t + 1000) do begin end;
asm
DB 0FH
DB 031H
mov nhi,edx
mov nlo,eax
end;
chi := mhi;
if mhi < 0 then chi := chi + shr32;
clo := mlo;
if mlo < 0 then clo := clo + shr32;
t0 := chi * shr32 + clo;
chi := nhi;
if nhi < 0 then chi := chi + shr32;
clo := nlo;
if nlo < 0 then clo := clo + shr32;
t1 := chi * shr32 + clo;
Result := (t1 - t0) / 1E6;
end;
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】