取得自從開機到現在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
//轉載請保留此信息
作者Blog:
http://blog.csdn.Net/ypyrock/
相關文章
get CPU id (很全的)
取得某一dll所有輸出函數名
取得自從開機到現在CPU運行的周期數,超毫秒級的精度
全透明窗體(效果比較好)
用winspool取得本機安裝的打印機的詳細信息
對該文的評論
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;