Debian Codegraph @

third_party/rust/neqo-transport/benches/transfer.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::{hint::black_box, time::Duration};
8
9 use criterion::{criterion_group, criterion_main, BatchSize::SmallInput, Criterion};
10 use neqo_transport::{ConnectionParameters, State};
11 use test_fixture::{
12 boxed,
13 sim::{
14 connection::{ConnectionNode, ReachState, ReceiveData, SendData},
15 network::{RandomDelay, TailDrop},
16 ReadySimulator, Simulator,
17 },
18 };
19
20 const ZERO: Duration = Duration::from_millis(0);
21 const JITTER: Duration = Duration::from_millis(10);
22 const TRANSFER_AMOUNT: usize = 1 << 22; // 4Mbyte
23
24 #[expect(
25 clippy::needless_pass_by_value,
26 reason = "Passing String where &str would do is fine here."
27 )]
28 fn benchmark_transfer(c: &mut Criterion, label: &str, seed: Option<impl AsRef<str>>) {
29 for pacing in [false, true] {
30 let mut group = c.benchmark_group(format!("transfer/pacing-{pacing}"));
31 // Don't let criterion calculate throughput, as that's based on wall-clock time, not
32 // simulator time.
33 group.noise_threshold(0.03);
34 group.bench_function(label, |b| {
35 b.iter_batched(
36 || {
37 let nodes = boxed![
38 ConnectionNode::new_client(
39 ConnectionParameters::default()
40 .pmtud(true)
41 .pacing(pacing)
42 .mlkem(false),
43 boxed![ReachState::new(State::Confirmed)],
44 boxed![SendData::new(TRANSFER_AMOUNT)]
45 ),
46 TailDrop::dsl_uplink(),
47 RandomDelay::new(ZERO..JITTER),
48 ConnectionNode::new_server(
49 ConnectionParameters::default()
50 .pmtud(true)
51 .pacing(pacing)
52 .mlkem(false),
53 boxed![ReachState::new(State::Confirmed)],
54 boxed![ReceiveData::new(TRANSFER_AMOUNT)]
55 ),
56 TailDrop::dsl_downlink(),
57 RandomDelay::new(ZERO..JITTER),
58 ];
59 let mut sim = Simulator::new(label, nodes);
60 if let Some(seed) = &seed {
61 sim.seed_str(seed);
62 }
63 sim.setup()
64 },
65 black_box(ReadySimulator::run),
66 SmallInput,
67 );
68 });
69 group.finish();
70 }
71 }
72
73 fn benchmark_transfer_variable(c: &mut Criterion) {
74 benchmark_transfer(c, "varying-seeds", std::env::var("SIMULATION_SEED").ok());
75 }
76
77 fn benchmark_transfer_fixed(c: &mut Criterion) {
78 benchmark_transfer(
79 c,
80 "same-seed",
81 Some("62df6933ba1f543cece01db8f27fb2025529b27f93df39e19f006e1db3b8c843"),
82 );
83 }
84
85 criterion_group! {
86 name = transfer;
87 config = Criterion::default().warm_up_time(Duration::from_secs(5)).measurement_time(Duration::from_secs(60));
88 targets = benchmark_transfer_variable, benchmark_transfer_fixed
89 }
90 criterion_main!(transfer);