calculate_bandwidth_mbps

Function calculate_bandwidth_mbps 

Source
pub fn calculate_bandwidth_mbps(bytes: Bytes, duration_ms: u64) -> f64
Expand description

Calculate bandwidth in Mbps from bytes and duration.

ยงExamples

use chie_shared::calculate_bandwidth_mbps;

// 1 MB transferred in 1 second = 8 Mbps
let bandwidth = calculate_bandwidth_mbps(1_000_000, 1000);
assert!((bandwidth - 8.0).abs() < 0.01);

// 10 MB in 2 seconds = 40 Mbps
let bandwidth = calculate_bandwidth_mbps(10_000_000, 2000);
assert!((bandwidth - 40.0).abs() < 0.01);

// Handle zero duration
let bandwidth = calculate_bandwidth_mbps(1_000_000, 0);
assert_eq!(bandwidth, 0.0);