- 0
- 0
- 约1.83千字
- 约 3页
- 2017-06-03 发布于广东
- 举报
Delphi高精度计时方法
发布于 软件开发网 来源 作者 佚名 时间
: :Duote : :2011-09-25
22:12
取毫秒级时间精度 方法一 :
// ( )
var
t1,t2:int64;
r1:int64;
begin
t1:=GetTickCount;//获取开始计数 WINDOWS API
sleep(1000);{do...}//执行要计时的代码
t2:=GetTickCount;//获取结束计数值
取得计时时间, 国 络 单位
r1:=t2-t1;// Y\` 4~ (}.u_%thV
毫秒(ms)
showmessage(inttostr(r1));
end;
取毫秒级时间精度 方法二 :
// ( )
//use DateUtils;//引用DateUtils单位
var
t1,t2:tdatetime;
r1:int64;
begin
t1:=now();//获取开始计时时间
sleep(1000);{do...}//执行要计时的代码
t2:=now();//获取结束计时时间
r1:=SecondsBetween(t2,t1);//取得计时时间,D6k=+W
的 育 单位秒
TsoUbP _II (s)
r1:=MilliSecondsBetween(t2,t1);//取得计时时间,
fTVGgU8E36
单位毫秒(ms)
showmessage(inttostr(r1));
end;
注:以上两种方式经本人测试好像只能产生 秒的计时精
// 0.01
度
取系统级时间精度:
//
var
c1:int64;
t1,t2:int64;
r1:double;
begin
QueryPerformanceFrequency(c1);//WINDOWS API
返回计数频率(Intel86:1193180)(获得系统的高性能频率计数
器在一毫秒内的震动次数)
QueryPerformanceCounter(t1);//WINDOWS API 获取
开始计数值
sleep(1000);{do...}//执行要计时的代码
QueryPerformanceCounter(t2);//获取结束计数值
r1:=(t2-t1)/c1;//取得计时时间,
件 育 软
L`:(Y\O }\^k( * {Ux
国 中
j5^ GZ,) 1a6t.1)Ti
提 教
x@\t)ac W
网 单位秒
YjTt]$1UCqSE) 7g (s)
r1:=(t2-t1)/c1*1000;//取得计时时间,单位毫秒(ms)
r1:=(t2-t1)/c1*1000000;//取得计时时间,单位微秒
showmessage(floattostr(r1));
end;
原创力文档

文档评论(0)