diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-01-30 14:22:34 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-30 14:12:14 +0100 |
commit | 904e1002b86c82647af99fa4b0eb587ccd219173 (patch) | |
tree | e39ef4391124e144528ce5c21e34fb132c2e646c /Userland/Utilities | |
parent | bdda1600d06cac6ea47ce18b7f9a74042f4d66a2 (diff) | |
download | serenity-904e1002b86c82647af99fa4b0eb587ccd219173.zip |
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.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/pro.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Utilities/pro.cpp b/Userland/Utilities/pro.cpp index ba729b4e23..0a64b78aac 100644 --- a/Userland/Utilities/pro.cpp +++ b/Userland/Utilities/pro.cpp @@ -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) { |