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. URAL 1057 Amount of Degrees (数位dp)

    Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly ...

  2. 新手指南:DVWA-1.9全级别教程之SQL Injection

    *本文原创作者:lonehand,转载须注明来自FreeBuf.COM 目前,最新的DVWA已经更新到1.9版本(http://www.dvwa.co.uk/),而网上的教程大多停留在旧版本,且没有针 ...

  3. HTML CSS + DIV实现排版布局

    HTML CSS + DIV实现排版布局 1.网页可以看成是由一个一个"盒子"组成,如图: 由上图可以看出,页面分为上(网站导航).中.下(版权声明)三个部分,中间部分又分为左(商 ...

  4. java并发编程笔记(三)——线程安全性

    java并发编程笔记(三)--线程安全性 线程安全性: ​ 当多个线程访问某个类时,不管运行时环境采用何种调度方式或者这些进程将如何交替执行,并且在主调代码中不需要任何额外的同步或协同,这个类都能表现 ...

  5. sublime useful packages

    Package control Prefixr Emmet

  6. cannot find module node-sass

    解决方法: npm install --save-dev node-sass

  7. alerttemplate 时间戳转换

    /*时间戳转换*/ template.defaults.imports.dateFmt = function(ns){ return new Date(parseInt(ns)).toLocaleSt ...

  8. Oracle高水位线(HWM)及性能优化

    说到HWM,我们首先要简要的谈谈ORACLE的逻辑存储管理.我们知道,ORACLE在逻辑存储上分4个粒度:表空间,段,区和块.    (1)块:是粒度最小的存储单位,现在标准的块大小是8K,ORACL ...

  9. find pattern

    daniel@daniel-mint ~/msf/metasploit-framework/tools $ ruby pattern_create.rb 2000 Aa0Aa1Aa2Aa3Aa4Aa5 ...

  10. python学习笔记:通配符之glob模块(过滤)

    glob模块用来查找文件目录和文件,可以和常用的find功能进行类比.glob支持*?[]这三种通配符.返回的数据类型是list.常见的两个方法有glob.glob()和glob.iglob(),ig ...