//取毫秒級(jí)時(shí)間精度(方法一):
var
t1,t2:int64;
r1:int64;
begin
t1:=GetTickCount;//獲取開始計(jì)數(shù) WINDOWS API
sleep(1000);{do...}//執(zhí)行要計(jì)時(shí)的代碼
t2:=GetTickCount;//獲取結(jié)束計(jì)數(shù)值
r1:=t2-t1;//取得計(jì)時(shí)時(shí)間,Y\`國4~絡(luò)(}.u_%t"hV單位毫秒(ms)
showmessage(inttostr(r1));
end;
//取毫秒級(jí)時(shí)間精度(方法二):
//use DateUtils;//引用DateUtils單位
var
t1,t2:tdatetime;
r1:int64;
begin
t1:=now();//獲取開始計(jì)時(shí)時(shí)間
sleep(1000);{do...}//執(zhí)行要計(jì)時(shí)的代碼
t2:=now();//獲取結(jié)束計(jì)時(shí)時(shí)間
r1:=SecondsBetween(t2,t1);//取得計(jì)時(shí)時(shí)間,D6k=+W的TsoUbP育_II單位秒(s)
r1:=MilliSecondsBetween(t2,t1);//取得計(jì)時(shí)時(shí)間,
fTVGgU8E36
單位毫秒(ms)
showmessage(inttostr(r1));
end;
//注:以上兩種方式經(jīng)本人測(cè)試好像只能產(chǎn)生0.01秒的計(jì)時(shí)精度
//取系統(tǒng)級(jí)時(shí)間精度:
var
c1:int64;
t1,t2:int64;
r1:double;
begin
QueryPerformanceFrequency(c1);//WINDOWS API 返回計(jì)數(shù)頻率(Intel86:1193180)(獲得系統(tǒng)的高性能頻率計(jì)數(shù)器在一毫秒內(nèi)的震動(dòng)次數(shù))
QueryPerformanceCounter(t1);//WINDOWS API 獲取開始計(jì)數(shù)值
sleep(1000);{do...}//執(zhí)行要計(jì)時(shí)的代碼
QueryPerformanceCounter(t2);//獲取結(jié)束計(jì)數(shù)值
r1:=(t2-t1)/c1;//取得計(jì)時(shí)時(shí)間,
L`:(Y\O件}\^k(育*軟{Ux
j5^國GZ,)中1a6t."1)Ti
x@\t)ac提W教
YjTt]$1UCqS'E)網(wǎng)7g單位秒(s)
r1:=(t2-t1)/c1*1000;//取得計(jì)時(shí)時(shí)間,單位毫秒(ms)
r1:=(t2-t1)/c1*1000000;//取得計(jì)時(shí)時(shí)間,單位微秒
showmessage(floattostr(r1));
end;
![]() | ![]() .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |
![]() | ![]() .. 定價(jià):¥133 優(yōu)惠價(jià):¥133.0 更多書籍 |