[Lazarus] Portable way to get accurate timestamps?

Michael Van Canneyt michael at freepascal.org
Tue Feb 22 08:50:33 CET 2011



On Tue, 22 Feb 2011, Bo Berglund wrote:

> On Mon, 21 Feb 2011 07:23:54 +0100, Bo Berglund
> <bo.berglund at gmail.com> wrote:
>
>> When I run a test against a fairly accurate GPS time source I see that
>> there is an uncertainty of about 16 ms in the time given such that if
>> GetTickCount is executed at exactly 1 second intervals the last two
>> digits of the value is not the same as it should be.
>> Instead it slowly (over a period of 16 seconds) reduces by 16 ms and
>> then suddenly restores to a max value.
>> It is like a superimposed sawtooth with an amplitude of 16 ms.
>>
>> The posted variation is apparently a Linux platform compatible version
>> that returns a millisecond value the same way as the Windows version
>> does, since there is no Windows GetTickCount API call in Linux.
>>
>> I used this also on Windows in my tests and then the value does not
>> exhibit the sawtooth anymore. So I assume that Now() gets its time
>> from another source than the timer counter driving GetTickCount and
>> this is more accurate.
>
> 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.

Michael.




More information about the Lazarus mailing list