站内搜索:     
站点首页破釜学院编程开发Delphi → 取得自从开机到现在CPU运行的周期数,超毫秒级的精度
正在加载相关信息.....
Web 站内搜索
取得自从开机到现在CPU运行的周期数,超毫秒级的精度
】【打印】【加入收藏】【关闭收藏到新浪ViVi】【收藏到365KEY】 浏览字号:
日期:2004-08-13 人气: 出处:csdn 作者: ypyrock [原作]

取得自从开机到现在CPU运行的周期数,超毫秒级的精度
function Ticker : DWord; register;
begin
  asm
          push EAX
          push EDX
          db $0f,$31
          mov Result, EAX
          pop EDX
          pop EAX
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 showmessage(inttostr( Ticker));
end;

//rock
//转载请保留此信息


相关文章
对该文的评论
black_fox ( 2002-08-23)
贴老外的贴子。异曲同共之妙。。。
const
  D32               = $66;

function RDTSC: comp;
var
  TimeStamp         : record
    case byte of
      1: (Whole: comp);
      2: (Lo, Hi: LongInt);
  end;
begin
  asm
db $0F; db $31; {BASM doesn't support RDTSC}
        {Pentium RDTSC - Read Time Stamp Counter - instruction}
{$ifdef Cpu386}
mov [TimeStamp.Lo],eax // the low dword
mov [TimeStamp.Hi],edx // the high dword
{$else}
db D32
mov word ptr TimeStamp.Lo,AX
        {mov [TimeStamp.Lo],eax - the low dword}
db D32
mov word ptr TimeStamp.Hi,DX
        {mov [TimeStamp.Hi],edx - the high dword}
{$endif}
  end;
  Result := TimeStamp.Whole;
end;


type
  CompStr = string[25];
  {Comps have up to 18 digits, plus commas, and sign}

function CompToStr(N: comp): CompStr;
var
  Low3              : string[3];
  N1                : extended;
begin
  if N < 0
    then Result := '-' + CompToStr(-N)
  else begin
      N1 := N / 1000;
      Str(Round(Frac(N1) * 1000), Low3);
      N := Int(N1);
      if N > 0
        then begin
          while Length(Low3) < 3 do Low3 := '0' + Low3;
          Result := CompToStr(N) + ThousandSeparator + Low3;
        end
      else Result := Low3
    end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
//showmessage(inttostr( Ticker));
  memo1.Lines.Add(CompToStr(RDTSC));
end;

>>>> 进入论坛交流 <<<<

相关文章:
暂时没有相关文章