Debian Codegraph @

crt/s2n/bindings/rust/standard/benchmarks/benches/throughput.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 use benchmarks::*;
5 use criterion::{
6 criterion_group, criterion_main, measurement::WallTime, BatchSize, BenchmarkGroup, Criterion,
7 Throughput,
8 };
9 use strum::IntoEnumIterator;
10 use tls_harness::{
11 cohort::{OpenSslConnection, RustlsConnection, S2NConnection},
12 harness::TlsInfo,
13 Mode, SigType, TlsConnPair, TlsConnection,
14 };
15
16 fn bench_throughput_for_library<T>(
17 bench_group: &mut BenchmarkGroup<WallTime>,
18 shared_buf: &mut [u8],
19 cipher_suite: CipherSuite,
20 ) where
21 T: TlsConnection + TlsInfo,
22 T::Config: TlsBenchConfig,
23 {
24 let crypto_config = CryptoConfig::new(cipher_suite, KXGroup::default(), SigType::default());
25 let client_config =
26 T::Config::make_config(Mode::Client, crypto_config, HandshakeType::default()).unwrap();
27 let server_config =
28 T::Config::make_config(Mode::Server, crypto_config, HandshakeType::default()).unwrap();
29
30 bench_group.bench_function(T::name(), |b| {
31 b.iter_batched_ref(
32 || -> TlsConnPair<T, T> {
33 let mut conn_pair = TlsConnPair::from_configs(&client_config, &server_config);
34 conn_pair.handshake().unwrap();
35 conn_pair
36 },
37 |conn_pair| {
38 let _ = conn_pair.round_trip_transfer(shared_buf);
39 },
40 BatchSize::SmallInput,
41 )
42 });
43 }
44
45 pub fn bench_throughput_cipher_suites(c: &mut Criterion) {
46 // arbitrarily large to cut across TLS record boundaries
47 let mut shared_buf = [0u8; 100000];
48
49 for cipher_suite in CipherSuite::iter() {
50 let mut bench_group = c.benchmark_group(format!("throughput-{cipher_suite:?}"));
51 bench_group.throughput(Throughput::Bytes(shared_buf.len() as u64));
52 bench_throughput_for_library::<S2NConnection>(
53 &mut bench_group,
54 &mut shared_buf,
55 cipher_suite,
56 );
57 bench_throughput_for_library::<RustlsConnection>(
58 &mut bench_group,
59 &mut shared_buf,
60 cipher_suite,
61 );
62 bench_throughput_for_library::<OpenSslConnection>(
63 &mut bench_group,
64 &mut shared_buf,
65 cipher_suite,
66 );
67 }
68 }
69
70 criterion_group! {benches, bench_throughput_cipher_suites}
71 criterion_main!(benches);