Last active: a year ago
use anyhow::Result;
use tokio::time::Instant;
#[tokio::main]
async fn main() -> Result<()> {
let start = Instant::now();
let client = reqwest::Client::new();
let mut res = client
.get("https://speed.hetzner.de/100MB.bin")
.send()
.await?;
let latency: u128 = start.elapsed().as_millis();
println!("latency: {latency}ms");
let download_start = Instant::now();
// let len = res.content_length().unwrap();
// res.bytes().await?;
// let time = download_start.elapsed().as_nanos() as f64 / 1_000_000_000 as f64;
// let bytes_per_second = len / time as u64;
// println!("bytes per second: {}", bytes_per_second);
let mut len = 0;
while let Some(c) = res.chunk().await? {
let time = download_start.elapsed().as_nanos() as f64 / 1_000_000_000 as f64;
len += c.len();
let bytes_per_second = len as f64 / time as f64;
dbg!(&bytes_per_second);
}
Ok(())
}