getUTCtime() increases irregularly
david
tazz at gmx.at
Wed Apr 4 16:02:45 PDT 2007
Frits van Bommel schrieb:
> david wrote:
>> I was just playing with a slow down class, when I noticed
>> getUTCtime() from std.date works a bit unexpected:
>>
>> import std.stdio;
>> import std.date : getUTCtime;
>>
>> int main(char[][] args)
>> {
>> for (int i=0;i<500;i++)
>> writefln(getUTCtime());
>> return 0;
>> }
>>
>> results in (shortened version, for obvious reasons):
>>
> [snip]
>>
>> So, it increases as well in large increments
>> and also in irregular ones, namely
>> 15 and 16 milliseconds.
>>
>> Since I found nothing in the phobos docs,
>> how can I access the current time at a more
>> precise level?
>
> The precision of the clock is operating-system dependent AFAIK.
> (including the version of the OS and obviously the type of machine it's
> running on)
> D can't make it more accurate than the OS is willing to provide :(.
>
> (Your post header indicates you're running Windows)
> On Windows, there are (at least) two functions to get the current time:
> one returns it as a SYSTEMTIME structure, one as a FILETIME structure.
> It looks like std.date uses GetSystemTime; you could try to see if
> GetFileTime is more accurate. (no idea why it would be, but you could
> try...)
> Try this:
> ---
> import std.c.windows.windows : GetSystemTimeAsFileTime, FILETIME;
> import std.date;
>
> d_time currentFileTime() {
> FILETIME ft;
> GetSystemTimeAsFileTime(&ft);
> return std.date.FILETIME2D_time(ft);
> }
> ---
> (Coded with no access to a Windows computer, so completely untested. I
> just had the std.date source and pages referenced from
> http://msdn2.microsoft.com/en-us/library/ms725479.aspx to work with)
Thanks for the idea,
but as you thought the precision is the same,
d_time currentFileTime()
{
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
return std.date.FILETIME2d_time(&ft);
}
yields the same result as getUTCtime().
(And for that matter, as a direct GetSystemTime().)
More information about the Digitalmars-d-learn
mailing list