Vb教程   Vb.net教程   Vfp教程   C/C++教程   Vc/Vc++教程   Delphi教程   Java教程   Powerbuilder
  杀毒频道 | 短信频道 | 网络电视 | 论文中心 | 教你学上网 | 教你学软件 | 网页特效 | 电脑基础 | 论坛  
  计算机等级 | 程序员考试 | 英语四六级 | 职称英语 | 司法考试 | 报关员考试 | 公务员考试 | 翻译员考试 | 注册会计师  
  Html教程 | Css教程 | Xml教程 | Asp教程 | Asp.net | Php教程 | Jsp教程 | Linux教程 | QQ技巧  
Photoshop Illustrator ImageReady Maya教程 3D Max教程 Lightscape Coredraw教程 Authorware Autocad教程 Freehand教程
Access教程 Mysql教程 Sql server Oracle教程 Word教程 Excel教程 Powerpoint Frontpage Asp.net源码 Php源代码
Flash教程 Fireworks Dreamweaver C#教程 outlook教程 系统安装 vbscript教程 Javascript Jsp源代码 Asp源代码
您的位置:首页 >> delphi教程 >> 正文

Delphi高精度计时方法
文章来源:csdn 作者:yzsind

 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;

[返回]

     

首页 | 设为首页 | 加入收藏 | 关于本站 | 友情链接 | 版权声明

     
 
Copyright© www.bianceng.cn Powered by 编程入门网 All Rights Reserved
吉ICP备06005558号