mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-23 19:17:44 -05:00
reuse reqwest client in serve_camera_html bench
This makes a huge difference in the reported time - 863 usec rather than 6 milliseconds on my laptop. Part of the difference is in reqwest client setup (it apparently initializes a SSL_CTX that is never used in this test), part fresh connections vs keepalive, part I don't know what. None of it seems relevant to the logic I want to test.
This commit is contained in:
@@ -652,13 +652,15 @@ mod bench {
|
||||
let url = reqwest::Url::parse(&format!("{}/cameras/{}/", server.base_url,
|
||||
*testutil::TEST_CAMERA_UUID)).unwrap();
|
||||
let mut buf = Vec::new();
|
||||
b.iter(|| {
|
||||
let client = reqwest::Client::new().unwrap();
|
||||
let client = reqwest::Client::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();
|
||||
});
|
||||
};
|
||||
f(); // warm.
|
||||
b.iter(f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user