1use byte_unit::{AdjustedByte, Byte, UnitType};
6
7pub mod clock;
8pub mod simtime;
9
10#[must_use]
12pub fn compute_adjusted_value_and_rate(
13 time_now_ns: f64,
14 num_bytes: usize,
15) -> (AdjustedByte, AdjustedByte) {
16 let time_now_s = time_now_ns / (1000.0 * 1000.0 * 1000.0);
17 let count = Byte::from_u64(num_bytes as u64).get_appropriate_unit(UnitType::Binary);
18 let per_second = if time_now_s == 0.0 {
19 Byte::from_f64(0.0).unwrap()
20 } else {
21 Byte::from_f64(num_bytes as f64 / time_now_s).unwrap()
22 };
23 let count_per_second = per_second.get_appropriate_unit(UnitType::Binary);
24 (count, count_per_second)
25}