progress: when possible, calculate transfer speeds with microseconds

... this improves precision, especially for transfers in the few or even
sub millisecond range.

Reported-by: J. Bromley
Fixes #7017
Closes #7020
This commit is contained in:
Daniel Stenberg 2021-05-06 09:06:24 +02:00
parent 04cc27460e
commit 68027623e2
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
1 changed files with 8 additions and 2 deletions

View File

@ -384,13 +384,19 @@ static bool progress_calc(struct Curl_easy *data, struct curltime now)
timespent_ms = (curl_off_t)data->progress.timespent/1000; /* ms */
/* The average download speed this far */
if(dl < CURL_OFF_T_MAX/1000)
if(dl < CURL_OFF_T_MAX/1000000)
data->progress.dlspeed =
(dl * 1000000 / (data->progress.timespent?data->progress.timespent:1));
else if(dl < CURL_OFF_T_MAX/1000)
data->progress.dlspeed = (dl * 1000 / (timespent_ms>0?timespent_ms:1));
else
data->progress.dlspeed = (dl / (timespent>0?timespent:1));
/* The average upload speed this far */
if(ul < CURL_OFF_T_MAX/1000)
if(ul < CURL_OFF_T_MAX/1000000)
data->progress.ulspeed =
(ul * 1000000 / (data->progress.timespent?data->progress.timespent:1));
else if(ul < CURL_OFF_T_MAX/1000)
data->progress.ulspeed = (ul * 1000 / (timespent_ms>0?timespent_ms:1));
else
data->progress.ulspeed = (ul / (timespent>0?timespent:1));