gwr_engine/time/
mod.rs

1// Copyright (c) 2023 Graphcore Ltd. All rights reserved.
2
3//! Modules that model time within the simulations.
4
5use byte_unit::{AdjustedByte, Byte, UnitType};
6
7pub mod clock;
8pub mod simtime;
9
10// Convert a number of bytes to a binary-only unit (KiB, MiB, etc)
11#[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}