Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(bench): remove non-generic connection logic #4236

Merged
merged 8 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions bindings/rust/bench/benches/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bench::OpenSslConnection;
#[cfg(feature = "rustls")]
use bench::RustlsConnection;
use bench::{
CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, S2NConnection,
SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup,
Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
Expand All @@ -16,16 +16,19 @@ use pprof::criterion::{Output, PProfProfiler};
use std::error::Error;
use strum::IntoEnumIterator;

fn bench_handshake_for_library<T: TlsConnection>(
fn bench_handshake_for_library<T>(
bench_group: &mut BenchmarkGroup<WallTime>,
handshake_type: HandshakeType,
kx_group: KXGroup,
sig_type: SigType,
) {
) where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
// make configs before benching to reuse
let crypto_config = CryptoConfig::new(CipherSuite::default(), kx_group, sig_type);
let client_config = T::make_config(Mode::Client, crypto_config, handshake_type);
let server_config = T::make_config(Mode::Server, crypto_config, handshake_type);
let client_config = T::Config::make_config(Mode::Client, crypto_config, handshake_type);
let server_config = T::Config::make_config(Mode::Server, crypto_config, handshake_type);

// generate all harnesses (TlsConnPair structs) beforehand so that benchmarks
// only include negotiation and not config/connection initialization
Expand Down
28 changes: 14 additions & 14 deletions bindings/rust/bench/benches/resumption.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use bench::{
CipherSuite, CryptoConfig, HandshakeType, KXGroup, S2NConnection, SigType, TlsConnPair,
TlsConnection,
harness::TlsBenchConfig, CipherSuite, CryptoConfig, HandshakeType, KXGroup, S2NConnection,
SigType, TlsConnPair, TlsConnection,
};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
};

fn bench_handshake_pair<T: TlsConnection>(
bench_group: &mut BenchmarkGroup<WallTime>,
sig_type: SigType,
) {
fn bench_handshake_pair<T>(bench_group: &mut BenchmarkGroup<WallTime>, sig_type: SigType)
where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
// generate all harnesses (TlsConnPair structs) beforehand so that benchmarks
// only include negotiation and not config/connection initialization
for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] {
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| {
b.iter_batched_ref(
|| {
TlsConnPair::<T, T>::new(
TlsConnPair::<T, T>::new_bench_pair(
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type),
handshake,
Default::default(),
)
},
|conn_pair_res| {
Expand All @@ -33,18 +33,18 @@ fn bench_handshake_pair<T: TlsConnection>(
}
}

fn bench_handshake_server_1rtt<T: TlsConnection>(
bench_group: &mut BenchmarkGroup<WallTime>,
sig_type: SigType,
) {
fn bench_handshake_server_1rtt<T>(bench_group: &mut BenchmarkGroup<WallTime>, sig_type: SigType)
where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
for handshake in [HandshakeType::Resumption, HandshakeType::ServerAuth] {
bench_group.bench_function(format!("{:?}-{}", handshake, T::name()), |b| {
b.iter_batched_ref(
|| {
let pair = TlsConnPair::<T, T>::new(
let pair = TlsConnPair::<T, T>::new_bench_pair(
CryptoConfig::new(CipherSuite::default(), KXGroup::default(), sig_type),
handshake,
Default::default(),
)
.unwrap();
let (mut c, s) = pair.split();
Expand Down
15 changes: 9 additions & 6 deletions bindings/rust/bench/benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bench::OpenSslConnection;
#[cfg(feature = "rustls")]
use bench::RustlsConnection;
use bench::{
CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup, Mode, S2NConnection,
SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
harness::TlsBenchConfig, CipherSuite, ConnectedBuffer, CryptoConfig, HandshakeType, KXGroup,
Mode, S2NConnection, SigType, TlsConnPair, TlsConnection, PROFILER_FREQUENCY,
};
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
Expand All @@ -17,14 +17,17 @@ use pprof::criterion::{Output, PProfProfiler};
use std::error::Error;
use strum::IntoEnumIterator;

fn bench_throughput_for_library<T: TlsConnection>(
fn bench_throughput_for_library<T>(
bench_group: &mut BenchmarkGroup<WallTime>,
shared_buf: &mut [u8],
cipher_suite: CipherSuite,
) {
) where
T: TlsConnection,
T::Config: TlsBenchConfig,
{
let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default());
let client_config = T::make_config(Mode::Client, crypto_config, HandshakeType::default());
let server_config = T::make_config(Mode::Server, crypto_config, HandshakeType::default());
let client_config = T::Config::make_config(Mode::Client, crypto_config, HandshakeType::default());
let server_config = T::Config::make_config(Mode::Server, crypto_config, HandshakeType::default());

bench_group.bench_function(T::name(), |b| {
b.iter_batched_ref(
Expand Down
Loading
Loading