mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:17:46 +00:00
pro: Use a rolling average for the download rate calculation
This makes it jump around less, and give a decent-ish representation of download speed.
This commit is contained in:
parent
bdda1600d0
commit
904e1002b8
1 changed files with 10 additions and 3 deletions
|
@ -213,7 +213,9 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
u32 previous_downloaded_size { 0 };
|
||||
timeval prev_time, current_time, time_diff;
|
||||
u32 previous_midpoint_downloaded_size { 0 };
|
||||
timeval prev_time, prev_midpoint_time, current_time, time_diff;
|
||||
static constexpr auto download_speed_rolling_average_time_in_ms = 4000;
|
||||
gettimeofday(&prev_time, nullptr);
|
||||
|
||||
bool received_actual_headers = false;
|
||||
|
@ -235,8 +237,13 @@ int main(int argc, char** argv)
|
|||
|
||||
fprintf(stderr, " at %s/s", human_readable_size(((float)size_diff / (float)time_diff_ms) * 1000).characters());
|
||||
|
||||
previous_downloaded_size = downloaded_size;
|
||||
prev_time = current_time;
|
||||
if (time_diff_ms >= download_speed_rolling_average_time_in_ms) {
|
||||
previous_downloaded_size = previous_midpoint_downloaded_size;
|
||||
prev_time = prev_midpoint_time;
|
||||
} else if (time_diff_ms >= download_speed_rolling_average_time_in_ms / 2) {
|
||||
previous_midpoint_downloaded_size = downloaded_size;
|
||||
prev_midpoint_time = current_time;
|
||||
}
|
||||
};
|
||||
|
||||
if (save_at_provided_name) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue