Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->Delphi ->正文

取得自从开机到现在CPU运行的周期数,超毫秒级的精度

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-05 点击: [收藏] [投稿]

取得自从开机到现在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;


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:提取win98上网密码   下一篇:取得某一dll所有输出函数名

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章