一
TTtimer控件的實質是調用Windows API定時函數SetTimer和KillTimer來實現的
Sleep函數用來使程序的執行延時給定的時間值
sleep(
Sleep會引起程序停滯
在主程序中延時
procedure Delay(MSecs: Longint);
//延時函數
var
FirstTickCount
begin
FirstTickCount := GetTickCount();
repeat
Application
Now := GetTickCount();
until (Now
end;
二
為了比較以上方法的精度
)
{
A high
downto microsec
Quick Reference:
THPCounter inherits from TComponent
Key
Start: Starts the counter
code you want to measure
Read: Reads the counter as a string
after the code you want to measure
ReadInt: Reads the counter as an Int
after the code you want to measure
}
unit HPCounter;
interface
uses
SysUtils
Forms
type
TInt
THPCounter = class(TComponent)
private
Frequency: TLargeInteger;
lpPerformanceCount
lpPerformanceCount
fAbout: string;
procedure SetAbout(Value: string);
{ Private declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Start;
function Read: string;
function ReadInt: TLargeInteger;
{ Private declarations }
published
property About: string read fAbout write SetAbout;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents(
end;
constructor THPCounter
begin
inherited Create(AOwner);
fAbout:=
end;
destructor THPCounter
begin
inherited Destroy;
end;
function THPCounter
begin
QueryPerformanceCounter(TInt
QueryPerformanceFrequency(TInt
Result:=IntToStr(Round(
lpPerformanceCount
end;
function THPCounter
begin
QueryPerformanceCounter(TInt
QueryPerformanceFrequency(TInt
Result:=Round(
lpPerformanceCount
end;
procedure THPCounter
begin
Exit;
end;
procedure THPCounter
begin
QueryPerformanceCounter(TInt
end;
end
unit Unit
interface
uses
Windows
HPCounter
type
TForm
Button
Edit
Label
Label
procedure Button
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form
implementation
{$R *
procedure TForm
begin
Edit
Application
with THPCounter
begin
Start;
// Place code to measure here
Sleep(
// Place code to measure here
Edit
Free;
end;
end;
end
三
為了比較
實際延時時間(ms)
可見
From:http://tw.wingwit.com/Article/program/Delphi/201311/24673.html