TickDuration deprecation

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Nov 19 17:26:04 UTC 2017


On Sunday, November 19, 2017 16:55:06 Rumbu via Digitalmars-d wrote:
> On Sunday, 19 November 2017 at 16:02:34 UTC, Jonathan M Davis
>
> wrote:
> > Was the documentation on Duration not informative enough, or
> > did you have trouble finding it from the documentation for the
> > benchmarking functions, or something else? Simply converting a
> > Duration to a string gives you what I would have thought would
> > have been plenty human readable (though obviously not
> > necessarily what you want in all cases), and it's split and
> > total functions should make it straightforward to put the
> > result in some other format if that's what you want. Was the
> > documentation on those not enough?
> >
> > - Jonathan M Davis
>
> The documentation on Duration doesn't specify any method of
> converting it to usecs (that's what I need). TickDuration has a
> usecs member, I really don't care how many ticks are there.

Duration doesn't have any ticks. As its documentation states, it holds its
time internally in hecto-nanoseconds. Its total function can be used to
convert the entire Duration to whatever units you want:

https://dlang.org/phobos/core_time.html#.Duration.total

whereas its split function allows you to split it into whatever units you
want:

https://dlang.org/phobos/core_time.html#.Duration.split

And simply converting a Duration to a string prints out the units with them
split out in a human readable manner. e.g.

    writeln(usecs(502397292));

would print

8 minutes, 22 secs, 397 ms, and 292 μs

https://dlang.org/phobos/core_time.html#.Duration.toString

Subtracting MonoTimes specifically gives a Duration rather than a
TickDuration or anything else representing the number of ticks, because you
don't normally care about the number of ticks, and its cleaner to have only
one duration type. Anyone who wants the number of ticks would have to use
MonoTime's ticks property to get at them and then subtract those directly.

So, anything holding the monotonic time now uses MonoTime to hold the times
and gives the length of time as a Duration.

- Jonathan M Davis




More information about the Digitalmars-d mailing list