| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
use benchmarks::*; |
| 5 |
use tls_harness::cohort::S2NConnection; |
| 6 |
|
| 7 |
use criterion::{ |
| 8 |
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion, |
| 9 |
}; |
| 10 |
use tls_harness::{harness::TlsInfo, SigType, TlsConnection}; |
| 11 |
|
| 12 |
fn bench_handshake_pair<T>(bench_group: &mut BenchmarkGroup<WallTime>, sig_type: SigType) |
| 13 |
where |
| 14 |
T: TlsConnection + TlsInfo, |
| 15 |
T::Config: TlsBenchConfig, |
| 16 |
{ |
| 17 |
|
| 18 |
|
| 19 |
for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] { |
| 20 |
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| { |
| 21 |
b.iter_batched_ref( |
| 22 |
|| { |
| 23 |
new_bench_pair::<T, T>( |
| 24 |
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type), |
| 25 |
handshake, |
| 26 |
) |
| 27 |
}, |
| 28 |
|conn_pair_res| { |
| 29 |
if let Ok(conn_pair) = conn_pair_res { |
| 30 |
let _ = conn_pair.handshake(); |
| 31 |
} |
| 32 |
}, |
| 33 |
BatchSize::SmallInput, |
| 34 |
) |
| 35 |
}); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
fn bench_handshake_server_1rtt<T>(bench_group: &mut BenchmarkGroup<WallTime>, sig_type: SigType) |
| 40 |
where |
| 41 |
T: TlsConnection + TlsInfo, |
| 42 |
T::Config: TlsBenchConfig, |
| 43 |
{ |
| 44 |
for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] { |
| 45 |
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| { |
| 46 |
b.iter_batched_ref( |
| 47 |
|| { |
| 48 |
let mut pair = new_bench_pair::<T, T>( |
| 49 |
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type), |
| 50 |
handshake, |
| 51 |
) |
| 52 |
.unwrap(); |
| 53 |
pair.client_mut().handshake().unwrap(); |
| 54 |
pair |
| 55 |
}, |
| 56 |
|pair| { |
| 57 |
|
| 58 |
|
| 59 |
pair.server_mut().handshake().unwrap(); |
| 60 |
}, |
| 61 |
BatchSize::SmallInput, |
| 62 |
) |
| 63 |
}); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
pub fn bench_resumption(c: &mut Criterion) { |
| 71 |
|
| 72 |
for sig_type in [SigType::Rsa2048, SigType::Ecdsa256] { |
| 73 |
let mut bench_group = c.benchmark_group(format!("resumption-pair-{sig_type:?}")); |
| 74 |
bench_handshake_pair::<S2NConnection>(&mut bench_group, sig_type); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
for sig_type in [SigType::Rsa2048, SigType::Ecdsa384] { |
| 80 |
let mut bench_group = c.benchmark_group(format!("resumption-server-1rtt-{sig_type:?}")); |
| 81 |
bench_handshake_server_1rtt::<S2NConnection>(&mut bench_group, sig_type); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
criterion_group!(benches, bench_resumption); |
| 86 |
criterion_main!(benches); |