Delphi高精度计时方法 |
//取毫秒级 工夫精度( 步骤一): var t1,t2:int64; r1:int64; begin t1:=GetTickCount;//猎取开始计数 WINDOWS API sleep(1000);{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(1000);{do...}//执行要计时的代码 t2:=now();//猎取 完毕计时 工夫 r1:=SecondsBetween(t2,t1);// 获得计时 工夫,D6k=+W的TsoUbP育_II单位秒(s) r1:=MilliSecondsBetween(t2,t1);// 获得计时 工夫, fTVGgU8E36 单位毫秒(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;// 获得计时 工夫, L`:(Y\O件}\^k(育*软{Ux j5^国GZ,)中1a6t."1)Ti x@\t)ac提W教 YjTt]$1UCqS'E)网7g单位秒(s) r1:=(t2-t1)/c1*1000;// 获得计时 工夫,单位毫秒(ms) r1:=(t2-t1)/c1*1000000;// 获得计时 工夫,单位微秒 showmessage(floattostr(r1)); end; |