//Get millisecond-level time accuracy (Method 1):
var
t1,t2:int64;
r1:int64;
Begin
t1:=GetTickCount;//Get Start Counting WINDOWS API
sleep(1000);{do...}//Execute the code to be timed
t2:=GetTickCount;//Get the end count value
r1:=t2-t1;//Get the timing time, unit milliseconds (ms)
showmessage(inttostr(r1));
end;
//Get millisecond-level time accuracy (Method 2):
//use DateUtils;//reference DateUtils unit
var
t1,t2:tdatetime;
r1:int64;
Begin
t1:=now();//Get the start time
sleep(1000);{do...}//Execute the code to be timed
t2:=now();//Get the end time
r1:=SecondsBetween(t2,t1);//Get the timing time, unit seconds (s)
r1:=MilliSecondsBetween(t2,t1);//Get the timing time, unit milliseconds (ms)
showmessage(inttostr(r1));
end;
//Note: After testing the above two methods, it seems that they can only produce 0.01 seconds of timing accuracy after testing by myself.
//Get system-level time accuracy:
var
c1:int64;
t1,t2:int64;
r1:double;
Begin
QueryPerformanceFrequency(c1);//WINDOWS API returns the counting frequency (Intel86:1193180) (gets the number of vibrations of the system's high-performance frequency counter in one millisecond)
QueryPerformanceCounter(t1);//WINDOWS API Get the start count value
sleep(1000);{do...}//Execute the code to be timed
QueryPerformanceCounter(t2);//Get the end count value
r1:=(t2-t1)/c1;//Get the timing time, unit seconds (s)
r1:=(t2-t1)/c1*1000;//Get the timing time, unit milliseconds (ms)
r1:=(t2-t1)/c1*1000000;//Get the timing time, unit microseconds
showmessage(floattostr(r1));
end;