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:
Scott Lamb
2017-03-03 22:26:29 -08:00
parent 1cf27c189f
commit 4806c62ca1
3 changed files with 14 additions and 4 deletions

View File

@@ -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);
}
}