aquatic_http: serialize responses to a buffer ref instead of new vec

This improves benchmark performance somewhat and performance
during load testing a bit too.
This commit is contained in:
Joakim Frostegård 2020-07-24 21:58:41 +02:00
parent 228511b3aa
commit fd68a5f603
7 changed files with 1101 additions and 1089 deletions

View file

@ -26,9 +26,14 @@ pub fn bench(c: &mut Criterion) {
let response = Response::Announce(announce_response);
c.bench_function("announce-response-to-bytes", |b| b.iter(||
Response::to_bytes(black_box(&response))
));
let mut buffer = [0u8; 4096];
let mut buffer = ::std::io::Cursor::new(&mut buffer[..]);
c.bench_function("announce-response-to-bytes", |b| b.iter(|| {
buffer.set_position(0);
Response::write(black_box(&response), black_box(&mut buffer)).unwrap();
}));
}
criterion_group!{