[Lazarus] How to program with time in milliseconds?

Michael Van Canneyt michael at freepascal.org
Thu May 15 13:43:42 CEST 2014



On Thu, 15 May 2014, Henry Vermaak wrote:

> On Thu, May 15, 2014 at 11:41:32AM +0200, Michael Schnell wrote:
>> On 05/15/2014 11:18 AM, Michael Van Canneyt wrote:
>>>
>>>
>>> fpGetTimeOfDay is used to implement Now(). This should not be changed.
>>
>> Why not, If there are better ways ?
>
> "Better" needs to be defined here.  If you mean "faster", then you need
> to call through the vDSO, so just link to the C library and use their
> implementation.  Chances are that you are linking to the C library
> anyway (we're on the lazarus list after all).  There isn't much reason
> for fpc to implement this, but perhaps it warrants a comment in the
> documentation (e.g. "glibc may have a much faster implementation that
> doesn't use a syscall, if you're worried about performance").
>
> gettimeofday() is the correct way to get the real wall clock time, there
> is no "better" way for fpc to implement it (except for using
> clock_gettime() with CLOCK_REALTIME, since technically gettimeofday() is
> obsolete).
>
> gettimeofday() is not what you want to use for a timer, though, since it
> will change when someone sets the time on the system.  In that case you
> want to use clock_gettime() with CLOCK_MONOTONIC, or even
> CLOCK_MONOTONIC_RAW (linux only).  GetTickCount64 will use this on
> linux, but it reduces the precision to milliseconds.
>
> You seem a bit confused about some of these things, and people are
> talking at cross purposes, so I'll end my part in the discussion
> here.

Henry, thank you for explaining it very clearly.

I no longer had the desire to do so.

Michael.




More information about the Lazarus mailing list