Resolution of core.time.Duration...

Alexander aldem+dmars at nk7.net
Tue May 17 04:44:21 PDT 2011


On 17.05.2011 12:34, Jonathan M Davis wrote:

> Also, the system clock definitely does not reach hnsecs on any system that I've seen.

  Duration (unlike TickDuration) is not tied to system clock only, AFAIK (at least, this is not mentioned in the documentation).

  Using rdtsc it is possible to obtain even more precision than 1ns.

  Also, Duration can be used to store intervals which are not really related to system clock at all.

> Or it would require splitting up the seconds and sub-seconds which makes the types take up 
> more space and makes the math that much worse.

  OK, though I don't think that 4 or 8 bytes more will really make any noticeable change (many Phobos/druntime structures are over-sized anyway, IMHO) - time values are not used in big arrays, usually.

  As to math - for most operations involving calendar computations only seconds are relevant, and math itself takes literally nanoseconds to execute - so only functions which actually require better precision may use more complex math.

  What could be done, though - is to hide the internal format (hnsecs), i.e. do not expose it to functions like Thread.sleep() with ulong argument.

/Alexander


More information about the Digitalmars-d mailing list