diff --git a/src/mp4.rs b/src/mp4.rs index 74c0627..225a0c6 100644 --- a/src/mp4.rs +++ b/src/mp4.rs @@ -2338,19 +2338,20 @@ mod bench { testutil::init(); let server = &*SERVER; let p = server.generated_len; - let mut buf = Vec::with_capacity(p as usize); b.bytes = p; let client = reqwest::Client::new(); + let mut rt = tokio::runtime::Runtime::new().unwrap(); let mut run = || { - let mut resp = - client.get(server.url.clone()) - .header(reqwest::header::RANGE, format!("bytes=0-{}", p - 1)) - .send() - .unwrap(); - buf.clear(); - use std::io::Read; - let size = resp.read_to_end(&mut buf).unwrap(); - assert_eq!(p, size as u64); + rt.block_on(async { + let resp = + client.get(server.url.clone()) + .header(reqwest::header::RANGE, format!("bytes=0-{}", p - 1)) + .send() + .await + .unwrap(); + let b = resp.bytes().await.unwrap(); + assert_eq!(p, b.len() as u64); + }); }; run(); // warm. b.iter(run); diff --git a/src/web.rs b/src/web.rs index 40ee2c0..554da0c 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1398,14 +1398,14 @@ mod bench { let server = &*SERVER; let url = reqwest::Url::parse(&format!("{}/api/cameras/{}/main/recordings", server.base_url, server.test_camera_uuid)).unwrap(); - let mut buf = Vec::new(); let client = reqwest::Client::new(); + let mut rt = tokio::runtime::Runtime::new().unwrap(); let mut f = || { - let mut resp = client.get(url.clone()).send().unwrap(); - assert_eq!(resp.status(), reqwest::StatusCode::OK); - buf.clear(); - use std::io::Read; - resp.read_to_end(&mut buf).unwrap(); + rt.block_on(async { + let resp = client.get(url.clone()).send().await.unwrap(); + assert_eq!(resp.status(), reqwest::StatusCode::OK); + let _b = resp.bytes().await.unwrap(); + }); }; f(); // warm. b.iter(f);