DELPHI高精度计时方法

//取毫秒级时间精度(方法一):
  var
   t1,t2:int64;
   r1:int64;
  begin
   t1:=GetTickCount;//获取开始计数 WINDOWS API
   sleep();{do...}//执行要计时的代码
  t2:=GetTickCount;//获取结束计数值
   r1:=t2-t1;//取得计时时间,Y\`国4~络(}.u_%t"hV单位毫秒(ms)
   showmessage(inttostr(r1));
  end;   //取毫秒级时间精度(方法二):
  //use DateUtils;//引用DateUtils单位
  var
   t1,t2:tdatetime;
   r1:int64;
  begin
  t1:=now();//获取开始计时时间
  sleep();{do...}//执行要计时的代码
  t2:=now();//获取结束计时时间
  r1:=SecondsBetween(t2,t1);//取得计时时间,D6k=+W的TsoUbP育_II单位秒(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();{do...}//执行要计时的代码
   QueryPerformanceCounter(t2);//获取结束计数值
   r1:=(t2-t1)/c1;//取得计时时间,   单位秒(s)
   r1:=(t2-t1)/c1*;//取得计时时间,单位毫秒(ms)
   r1:=(t2-t1)/c1*;//取得计时时间,单位微秒
   showmessage(floattostr(r1));
  end;

delphi 延迟函数

//延迟函数:方法一
procedure delay(msecs:integer);
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(msecs);
while (msecs > ) and (MsgWaitForMultipleObjects(, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs := Tick - GetTickcount;
end;
finally
CloseHandle(Event);
end; //延迟函数:方法二
procedure Delay(dwMilliseconds:DWORD);//Longint
var
iStart,iStop:DWORD;
begin
iStart := GetTickCount;
repeat
iStop := GetTickCount;
Application.ProcessMessages;
until (iStop - iStart) >= dwMilliseconds;
end; 方法三
procedure delay(msecs:integer); //延迟函数 比sleep好
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(msecs);
while (msecs > ) and (MsgWaitForMultipleObjects(, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
msecs := Tick - GetTickcount;
end;
finally
CloseHandle(Event);
end;

一段代码执行消耗的时间

 关键是用到一个库函数GetTickCount

【函数名】 GetTickCount

【返回值】 Long,以毫秒为单位

通常用来计算某个操作所使用的时间:
var: start_time : LONG; stop_time:LONG; begin:
start_time :=GetTickCount; 调用接口操作
stop_time :=GetTickCount; ShowMessage( IntToStr(stop_time - art_time));
end;

获取系统时间

var
DateTime:TDateTime;
i:string;
begin
DateTime:=now;
i:=DateToStr(DateTime)+' '+TimeToStr (DateTime);
lable1.caption:=i; FormatDateTime('hh:nn:ss',Now());
FormatDateTime('yyyy年mm月dd日 hh时nn分ss秒zzzz',now()); var
DateTime:TDateTime;
i:string;
ct:TSystemTime;
begin
DateTime:=now;
i:=DateToStr(DateTime)+' '+TimeToStr (DateTime);
//Label1.caption:=i;
//Label1.caption:=FormatDateTime('yyyy年mm月dd日 hh时nn分ss秒zz',now());
//GetSystemTime();
//GetLocalTime(ct);
//Label1.caption:=GetSystemTime(ct);//FormatDateTime('yyyy年mm月dd日 hh时nn分ss秒zz',GetSystemTime(ct));
end;

delphi 时间的更多相关文章

  1. delphi 时间格式操作

    FormatDateTime('yyyy-mm-dd hh:nn:ss',Now) FormatDateTime('hh:mm:ss:zz',Now) if (TimeOf(now) < pub ...

  2. Delphi 时间耗时统计

    处理事情: 数据处理过程中,速度很慢,无法准确定位分析是DB问题还是客户端处理问题,所以增加计时统计日志: Delphi计时首次使用,查阅资料,予以记录: var BgPoint, EdPoind: ...

  3. delphi时间日期函数

    unit DateProcess; interface const DayOfWeekStrings: ..] of String = ('SUNDAY', 'MONDAY', 'TUESDAY', ...

  4. Delphi 时间函数:关于时间精确的几个函数和方法

    //取毫秒级时间精度(方法一): var t1,t2:int64; r1:int64; begin t1:=GetTickCount;//获取开始计数 WINDOWS API sleep(1000); ...

  5. 怎么使用Delphi获取当前的时间,精确到毫秒

    先介绍一个可能比较常用的方法,获取当前时间 var datetime: string; begin datetime:= FormatDateTime('yyyy-mm-dd hh:mm:ss', N ...

  6. Delphi DateUtils时间单元

    Uses DateUtils //时间单元,非常有用. 记得引用这个单元,不然不能用. CompareDate 比较两个日期时间值日期部分的大小 CompareDateTime 比较两个日期时间值的大 ...

  7. delphi 最全日期格式_DateUtils时间单元说明

    DateUtils时间单元说明 CompareDate 函数 比较两个日期时间值日期部分的大小 CompareDateTime 函数 比较两个日期时间值的大小 CompareTime 函数 比较两个日 ...

  8. Delphi日期时间 UNIX

    Delphi日期时间,就是常见的 2014-05-02 10:37:35 --------------------------------------------------------------- ...

  9. Delphi的时间处理

    这几天因为自己要学习编写一个小程序中要用到一些时间处理.就在网上搜集一些教材学习到一般的应用,做个笔记,加深印象. 用上Delphi中相应的函数,Delphi的时间处理起来还是很容易的. Delphi ...

随机推荐

  1. Mybatis基于XML配置SQL映射器(一)

    Durid和Mybatis开发环境搭建 SpringBoot搭建基于Spring+SpringMvc+Mybatis的REST服务(http://www.cnblogs.com/nbfujx/p/76 ...

  2. java web项目的https配置

    1.进入到jdk下的bin目录 keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat.keystore -validity ...

  3. [CSP-S模拟测试]:卡常题/b(基环树+DP)

    题目描述 $ρ$有一个二分连通无向图,$X$方点.$Y$方点均为$n$个(编号为$1\sim n$).这个二分图比较特殊,每一个$Y$方点的度为$2$,一条黑色边,一条白色边.所有黑色边权值均为$a$ ...

  4. MySQL 下载,安装,配置windows 服务

    本次使用的是压缩包的方式是可以纯手动自己折腾各种配置... ok,闲话少叙,我们准备发车... 一.先要去mysql官网去下载压缩包咯 ①下载地址:https://dev.mysql.com/down ...

  5. linux下lamp.sh一键配置lamp环境流程

    linux下lamp.sh一键配置lamp环境流程 一.总结 一句话总结: 2.将网站从github上clone到/data/www/网站域名/ 3.更改网站目录权限:chown -R apache: ...

  6. Module not found: Error: Can't resolve '@babel/runtime/helpers/classCallCheck' and Module not found: Error: Can't resolve '@babel/runtime/helpers/defineProperty'

    These two mistakes are really just one mistake, This is because the following file @babel/runtime ca ...

  7. linux中errno及perror的应用

    1 perror 定义在头文件<stdlib.h>中 void perror(const char *s);函数说明 perror ( )用 来 将 上 一 个 函 数 发 生 错 误 的 ...

  8. 微信小程序 获取用户信息并保存登录状态

    微信小程序 获取用户信息并保存登录状态:http://www.360doc.com/content/18/0124/11/9200790_724662071.shtml

  9. flex属性设置

    flex是一个复合属性,所以有三个值设置,这也就造成了flex可以只设置一个值或两个值: 如果flex只设置一个值: 没有单位的数,则这个值是flex-grow, 并且flex-basis变为0 有单 ...

  10. 实现一个EventEmitter类,这个类包含以下方法: on/ once/fire/off

    实现一个EventEmitter类,这个类包含以下方法: on(监听事件,该事件可以被触发多次)- once(也是监听事件,但只能被触发一次)- fire(触发指定的事件)- off(移除指定事件的某 ...