mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
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:
parent
9df1f0ecc6
commit
4caf174da5
13 changed files with 2064 additions and 0 deletions
42
aquatic_http/benches/bench_announce_response_to_bytes.rs
Normal file
42
aquatic_http/benches/bench_announce_response_to_bytes.rs
Normal 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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue