[Lazarus] Portable way to get accurate timestamps?
Bo Berglund
bo.berglund at gmail.com
Tue Feb 22 13:55:36 CET 2011
On Tue, 22 Feb 2011 08:50:33 +0100 (CET), Michael Van Canneyt
<michael at freepascal.org> wrote:
>> I should have added that instead of a sawtooth like noise component
>> using Frac(Now()) * 24*3600 to get the second since midnight gives
>> random noise in the seconds values of about 3-4 ms.
>> Another observation is that there seems to be no data smaller than ms.
>> If I format this value as a float with more decimals than 3 I always
>> only see zeroes.
>
>That is logical, since TDateTime only is accurate to millisecond precision.
>
Granted that, but right now I am mostly interested in finding a way to
time an external event source such that I can measure the time between
events.
After googling a bit I have come up with the following, which is a
variation of a delay function that I created years ago in Delphi to
enable me to output pulses that are timed to milliseconds.
The delay is now converted to a time retrieval function:
function TForm1.GetMillisecondTime: Int64;
var
Freq,
Ts: Int64;
begin
QueryPerformanceCounter(Ts);
QueryPerformanceFrequency(Freq);
if (Ts = 0) or (Freq = 0) then exit;
Freq := Freq div 1000;
Result := TS div Freq;
end;
When I try this in Lazarus I get an "Identifier not found" error (not
surprising).
What should I do in order to get this to compile?
Any suitable unit to add to the uses clause?
--
Bo Berglund
Developer in Sweden
More information about the Lazarus
mailing list