[fpc-devel] Problem with Now() and time changed by ntpd

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Nov 2 16:12:49 CET 2011



On Wed, 2 Nov 2011, zeljko wrote:

> On Wednesday 02 of November 2011 15:47:46 you wrote:
>> On Wed, 2 Nov 2011, zeljko wrote:
>>> On Wednesday 02 of November 2011 14:53:05 you wrote:
>>>> You must do also a localtime_r after this call.
>>>> clock_gettime returns the same time as gettimeofday.
>>>
>>> But point IS in comparing clock_gettime() vs. gettimeofday() which is
>>> used by fpgettimeofday(). I don't see localtime_r() calls in current RTL
>>> Now().
>>
>> Ok.
>>
>> It turns out that Now() was doing a fpGettimeofday (for time) and a fptime
>> (for date), which is of course really stupid.
>
> Yes, I saw that after posted example.
>
>>
>> I improved that (it does one call only). So, new stats, 64-bit, no
>> optimizations:
>>
>> sb: >./unixclocks
>> RTL Now() with 10000000 calls = 3698 ms
>> Kernel clock_gettime() NowReal() with 10000000 calls = 6564 ms
>>
>> Revision 19572.
>>
>> The time is now less than the Libc time you posted (5085ms).
>
> I don't care about libc timing, but why clock_gettime() is so slower now ? It
> is called only once in my example. Are you sufre that RTL now() returns
> correct date/time ?

Yes. Of course I tested that first :-)

I assume your version is slower because you call epochtolocaltime twice, for
instance.

If I remove the second call (it's not needed anyway) then

RTL Now() with 100000 calls = 2337 ms 
Kernel clock_gettime() NowReal() with 100000 calls = 2344 ms

>> I can't test the libc version, but if you'd care to re-test using the above
>> revision of unix/sysutils.pp, and post the results, I'd be grateful.
>
> Sorry, but I don't want to use 2.7.1 until it's useable.

I attached the changed file.

Michael.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: su.zip
Type: application/zip
Size: 10143 bytes
Desc: 
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20111102/2ab20a6a/attachment.zip>


More information about the fpc-devel mailing list