aquatic_http: add criterion benchmark for announce response to bytes

Speedup of custom implementation compared to using bendy:

announce-response-to-bytes:

time:   [413.77 ns 415.34 ns 417.08 ns]
change: [-93.074% -93.021% -92.968%] (p = 0.00 < 0.01)
Performance has improved.
This commit is contained in:
Joakim Frostegård 2020-07-19 16:56:13 +02:00
parent 9df1f0ecc6
commit 4caf174da5
13 changed files with 2064 additions and 0 deletions

View file

@ -0,0 +1,42 @@
use std::net::Ipv4Addr;
use std::time::Duration;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use aquatic_http::protocol::response::*;
pub fn bench(c: &mut Criterion) {
let mut peers = Vec::new();
for i in 0..100 {
peers.push(ResponsePeer {
ip_address: Ipv4Addr::new(127, 0, 0, i),
port: i as u16
})
}
let announce_response = AnnounceResponse {
announce_interval: 120,
complete: 100,
incomplete: 500,
peers: ResponsePeerListV4(peers),
peers6: ResponsePeerListV6(Vec::new()),
};
let response = Response::Announce(announce_response);
c.bench_function("announce-response-to-bytes", |b| b.iter(||
Response::to_bytes(black_box(&response))
));
}
criterion_group!{
name = benches;
config = Criterion::default()
.sample_size(1000)
.measurement_time(Duration::from_secs(180))
.significance_level(0.01);
targets = bench
}
criterion_main!(benches);