您现在的位置:首页 >> 硬件系统 >> 硬件系统 >> 内容

Delphi中利用ASM获取当前CPU的速度

时间:2011/9/3 15:19:00 点击:

  核心提示:function GetCPUSpeed: Double; const DelayTime = 500; var TimerHi, TimerLo: DWORD; PriorityClass, Pri...
function GetCPUSpeed: 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 
    mov TimerLo, eax 
    mov TimerHi, edx 
  end; 
  Sleep(DelayTime); 
  asm 
    dw 310Fh 
    sub eax, TimerLo 
    sbb edx, TimerHi 
    mov TimerLo, eax 
    mov TimerHi, edx 
  end; 
  SetThreadPriority(GetCurrentThread, Priority); 
  SetPriorityClass(GetCurrentProcess, PriorityClass); 
  Result := TimerLo / (1000 * DelayTime); 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  ShowMessage(Format('Your CPU speed: %f MHz', [GetCPUSpeed])); 
end; 
{Note: 
You should call the GetCPUSpeed 
function more than 
one time to get a good result. }

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章 技术支持:深圳市麟瑞科技有限公司(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 粤ICP备10103342号