From 4944a5179c9559aca931157a64e7b7d211cc4d48 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Sun, 18 Oct 2020 18:09:13 +0200 Subject: [PATCH] fix(net): Float interval for network speed Before the time difference between two measurements was always an integer number, so for intervals < 1, you would always get 0 and for any other non-integer interval you would get skewed results. --- src/adapters/net.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/adapters/net.cpp b/src/adapters/net.cpp index d9a9ca59..ffc8f441 100644 --- a/src/adapters/net.cpp +++ b/src/adapters/net.cpp @@ -225,9 +225,10 @@ namespace net { * Format up- and download speed */ string network::format_speedrate(float bytes_diff, int minwidth) const { - const auto duration = m_status.current.time - m_status.previous.time; - float time_diff = std::chrono::duration_cast(duration).count(); - float speedrate = bytes_diff / (time_diff ? time_diff : 1); + // Get time difference in seconds as a float + const std::chrono::duration duration = m_status.current.time - m_status.previous.time; + float time_diff = duration.count(); + float speedrate = bytes_diff / time_diff; vector suffixes{"GB", "MB"}; string suffix{"KB"};