Why is this valued zeroed?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Fri Jan 12 05:14:12 UTC 2018
On Thursday, January 11, 2018 14:07:18 Ali Çehreli via Digitalmars-d-learn
wrote:
> On 01/11/2018 12:21 PM, Marc wrote:
> > I stuck at this and can't figure out the reason why the value of the
> > variable ds is 0 when I do this: startTime = MonoTime.currTime;
>
> It's not clear which of the two statements you're talking about.
>
> >> http.onProgress = (size_t dltotal, size_t dlnow,
> >>
> >> size_t ultotal, size_t ulnow) {
> >>
> >> if(dlNow > 0) {
> >>
> >> MonoTime endTime = MonoTime.currTime;
> >> Duration duration = endTime - startTime;
> >>
> >> long ds = duration.total!"seconds";
> >> writeln("duration!seconds = ", ds);
> >> startTime = MonoTime.currTime;
>
> I would remove the one above and keep the one below.
>
> >> startTime = MonoTime.currTime;
> >> http.perform();
>
> If you're trying to measure time between two onProgress() calls, as
> Steve noted, seconds is probably too large a unit.
And if all what you're doing is printing the value out, you might as well
just print the Duration directly rather than calling total.
Duration.toString returns the units in a human-readable format such as
"2 secs, 300 msecs, and 24 μs" or "29 msecs".
https://dlang.org/phobos/core_time.html#.Duration.toString
And if you're doing something like adding up the time spent, then you'd be
better off keeping it in a Duration than converting it to long holding
seconds or milliseconds or whatever.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list