如何测试CPU的速度?

hzcdc21 2002-05-10 10:28:42
在线等候!
...全文
395 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Billy_Chen28 2002-05-10
  • 打赏
  • 举报
回复
给你一个函数
function GetCPUSpeed: Double;
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;
ly_liuyang 2002-05-10
  • 打赏
  • 举报
回复
function GetCPUSpeed: Double;
const
DelayTime = 500; // measure time in ms
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
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);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
CpuSpeedEdit.Text:=FloatToStr(GetCPUSpeed);
end;
火鸟李国平 2002-05-10
  • 打赏
  • 举报
回复
也来试试我
hongyou 2002-05-10
  • 打赏
  • 举报
回复
mark
东方小黑 2002-05-10
  • 打赏
  • 举报
回复
我也来试试
和码帮主 2002-05-10
  • 打赏
  • 举报
回复
学习
Bob7946 2002-05-10
  • 打赏
  • 举报
回复
一个函数:

function TForm1.GetCpuSpeed: Extended;
var
t, mhi, mlo, nhi, nlo: dword;
shr32 : comp;
begin
shr32 := 65536;
shr32 := shr32 * 65536;
t := GetTickCount;
while t = GetTickCount do ;
asm
DB 0FH,031H // rdtsc
mov mhi,edx
mov mlo,eax
end;
while GetTickCount < (t + 1000) do ;
asm
DB 0FH,031H // rdtsc
mov nhi,edx
mov nlo,eax
end;
Result := ((nhi * shr32 + nlo) - (mhi * shr32 + mlo)) / 1E6;
end;
Bob7946 2002-05-10
  • 打赏
  • 举报
回复
一个函数:

function TForm1.GetCpuSpeed: Extended;
var
t, mhi, mlo, nhi, nlo: dword;
shr32 : comp;
begin
shr32 := 65536;
shr32 := shr32 * 65536;
t := GetTickCount;
while t = GetTickCount do ;
asm
DB 0FH,031H // rdtsc
mov mhi,edx
mov mlo,eax
end;
while GetTickCount < (t + 1000) do ;
asm
DB 0FH,031H // rdtsc
mov nhi,edx
mov nlo,eax
end;
Result := ((nhi * shr32 + nlo) - (mhi * shr32 + mlo)) / 1E6;
end;
browmeld 2002-05-10
  • 打赏
  • 举报
回复
function CPUSpeed: Double;
const
DelayTime = 500; // 时间单位是毫秒
var
TimerHi, TimerLo: DWORD;
PriorityClass, Priority: Integer;
begin
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);
end;


5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧