[phobos] std.datetime and tick types

Sean Kelly sean at invisibleduck.org
Tue Sep 28 07:40:50 PDT 2010


On Sep 27, 2010, at 10:08 PM, Robert Jacques wrote:
> 
> Well, if you make up a unit, then you can guarantee no one will have heard of it before. And really, learning the hecto SI prefix means someone will always understand what hectonanosecond means, as opposed to StdTick or Duration, etc, which would have a tendency to be quickly forgotten or confused with another library type from another language. As for typing, I would expect the 100ns unit to be mainly an internal thing. Most of the time I deal in microseconds/1000.0 (i.e. floating point milliseconds), when dealing with std.perf today.


The Boost TimeDuration struct has a ticks() method as well as a few methods describing the tick resolution.  So someone wanting to possibly avoid a conversion could do:

if (7 == x.num_fractional_digits())
    auto y = x.ticks();
else
    auto z = x.total_nanoseconds() / 100;

This is what I'm currently working with for durations in druntime (not yet committed).



More information about the phobos mailing list