当前位置:主页>Delphi教程>文章内容
DELPHI高精度计时方法
来源: 作者: 发布时间:2007-04-29  
 

//取毫秒级时间精度(方法一):
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的属性property和消息处理特点事件属性   下一篇:Delphi帮助里的虚拟键值表
 
  相关文章
·delphi的属性property和消息处理特点事
·Delphi帮助里的虚拟键值表
·自绘ListBox的两种效果
·Delphi2005学习笔记4——再谈NameSpace
·Delphi程序设计综合训练任务书
·网站上传漏洞利用程序
·在Access中创建表及如何指定字段类型
·序列化FastReport
·制作从屏幕右下角逐渐弹出的消息提示框
·delphi7找不到TBDEClientDataSet控件的
·在网络上进行摄像头视频通讯
·Dephi快捷健
 
【关闭窗口】
推荐本站资源
最新文章