Hyper slow body reading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies] | |
hyper = { version = "0.14", features = ["full"] } | |
tokio = { version = "1", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use hyper::{body::HttpBody, Client}; | |
use tokio::time::Instant; | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | |
for _ in 0..2 { | |
let start = Instant::now(); | |
// Still inside `async fn main`... | |
let client = Client::new(); | |
// Parse an `http::Uri`... | |
let uri = "http://registry.yarnpkg.com/react".parse()?; | |
// Await the response... | |
let mut resp = client.get(uri).await?; | |
// let mut buf: Vec<u8> = Vec::with_capacity(resp.size_hint().upper().unwrap_or(0) as usize); | |
let mut body = resp.into_body(); | |
while let Some(chunk) = body.data().await { | |
// buf.append(&mut chunk?.to_vec()); | |
} | |
// println!("{}", &String::from_utf8(buf).unwrap()[0..1]); | |
println!("MS: {}", start.elapsed().as_millis()); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment