导航

心动吧DELPHI网络书

自发研究:须要多维思想而且要想不可能为可能的人才能做到

« delphi编写的时出现 runtime error 216 at 数字 的解决方法Delphi 怎么写插件 »

delphi计时器:DELPHI高精度计时方法

//取毫秒级时间精度(方法一): 
var 
t1,t2:int64; 
r1:int64; 
begin 
t1:=GetTickCount;//获取开始计数 WINDOWS API 
sleep(1000);{do...}//执行要计时的代码 
t2:=GetTickCount;//获取结束计数值 
r1:=t2-t1;//取得计时时间,单位毫秒(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);//取得计时时间,单位秒(s) 
r1:=MilliSecondsBetween(t2,t1);//取得计时时间,单位毫秒(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;//取得计时时间,单位秒(s) 
r1:=(t2-t1)/c1*1000;//取得计时时间,单位毫秒(ms) 
r1:=(t2-t1)/c1*1000000;//取得计时时间,单位微秒 
showmessage(floattostr(r1)); 
end; 

 

原创文章如转载,请注明:转载自心动吧DELPHI网络书 [ http://www.abcxd.com/delphi/ ]

本文链接地址:http://www.abcxd.com/delphi/abcxddelphi/DELPHIAPI/delphi-QueryPerformanceFrequency.html

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

搜索内容

日历

Copyright ⊙ 2004-2009 心动吧 UrL:ABCXD.CoM All RiGhts Reserved