digitalmars.D.learn - Why is this valued zeroed?
- Marc (15/28) Jan 11 2018 I stuck at this and can't figure out the reason why the value of
- Steven Schveighoffer (3/36) Jan 11 2018 `total` truncates. So your time is less than 1 second.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/18) Jan 11 2018 I would remove the one above and keep the one below.
- Jonathan M Davis (11/32) Jan 11 2018 And if all what you're doing is printing the value out, you might as wel...
- Marc (6/22) Jan 12 2018 I do use that value as following:
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; if I remove that statement, the value of ds isn't zeroed, it has the actual number of seconds. But I can't figure out, ds is of integer type and such, it is copied, right? or is this related to the fact I'm setting it withi a callback function? here's the piece of code:import std.net.curl; auto http = HTTP(url); http.method = HTTP.Method.get;... the relevant part: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;if I put startTime = MonoTime.currTime, ds is zero, otherwise, if I remove it, ds has the actual value. startTime is first set right before http.perform() call:startTime = MonoTime.currTime; http.perform();(My goal is define the download transfer rate, different approachs for this are welcome)
Jan 11 2018
On 1/11/18 3: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; if I remove that statement, the value of ds isn't zeroed, it has the actual number of seconds. But I can't figure out, ds is of integer type and such, it is copied, right? or is this related to the fact I'm setting it withi a callback function? here's the piece of code:`total` truncates. So your time is less than 1 second. -Steveimport std.net.curl; auto http = HTTP(url); http.method = HTTP.Method.get;.... the relevant part: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;if I put startTime = MonoTime.currTime, ds is zero, otherwise, if I remove it, ds has the actual value. startTime is first set right before http.perform() call:startTime = MonoTime.currTime; http.perform();(My goal is define the download transfer rate, different approachs for this are welcome)
Jan 11 2018
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.I would remove the one above and keep the one below.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;If you're trying to measure time between two onProgress() calls, as Steve noted, seconds is probably too large a unit. AlistartTime = MonoTime.currTime; http.perform();
Jan 11 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
Jan 11 2018
On Friday, 12 January 2018 at 05:14:12 UTC, Jonathan M Davis wrote:On Thursday, January 11, 2018 14:07:18 Ali Çehreli via Digitalmars-d-learn wrote:I do use that value as following:[...]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 Davisint t = fileSize / countOfByetsDownloaded * duration.total!"seconds";I print that value there for testing only, if I was getting the values correctly. Thank you all guys for the answers.
Jan 12 2018