Debian Codegraph @

third_party/rust/neqo-transport/benches/sent_packets.rs

raw
1 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4 // option. This file may not be copied, modified, or distributed
5 // except according to those terms.
6
7 use std::{
8 hint::black_box,
9 time::{Duration, Instant},
10 };
11
12 use criterion::{criterion_group, criterion_main, Criterion};
13 use neqo_transport::{
14 packet::{PacketNumber, PacketType},
15 recovery::sent::{SentPacket, SentPackets},
16 };
17
18 fn sent_packets() -> SentPackets {
19 let mut pkts = SentPackets::default();
20 let now = Instant::now();
21 // Simulate high bandwidth-delay-product connection.
22 for i in 0..2_000u64 {
23 pkts.track(SentPacket::new(
24 PacketType::Short,
25 PacketNumber::from(i),
26 now,
27 true,
28 Vec::new(),
29 100,
30 ));
31 }
32 pkts
33 }
34
35 /// Confirm that taking a small number of ranges from the front of
36 /// a large span of sent packets is performant.
37 /// This is the most common pattern when sending at a higher rate.
38 /// New acknowledgments will include low-numbered packets,
39 /// while the acknowledgment rate will ensure that most of the
40 /// outstanding packets remain in flight.
41 fn take_ranges(c: &mut Criterion) {
42 c.bench_function("SentPackets::take_ranges", |b| {
43 b.iter_batched_ref(
44 sent_packets,
45 // Take the first 90 packets, minus some gaps.
46 |pkts| black_box(pkts.take_ranges([70..=89, 40..=59, 10..=29])),
47 criterion::BatchSize::SmallInput,
48 );
49 });
50 }
51
52 criterion_group! {
53 name = benches;
54 config = Criterion::default().warm_up_time(Duration::from_secs(5)).measurement_time(Duration::from_secs(60));
55 targets = take_ranges
56 }
57 criterion_main!(benches);