33
44use bench:: {
55 harness:: TlsBenchConfig , CipherSuite , CryptoConfig , HandshakeType , KXGroup , Mode ,
6- OpenSslConnection , RustlsConnection , S2NConnection , SigType , TlsConnPair , TlsConnection ,
7- PROFILER_FREQUENCY ,
6+ OpenSslConnection , RustlsConnection , S2NConnection , SigType , TlsConnPair , TlsConnection
87} ;
98use criterion:: {
109 criterion_group, criterion_main, measurement:: WallTime , BatchSize , BenchmarkGroup , Criterion ,
1110} ;
12- use pprof:: criterion:: { Output , PProfProfiler } ;
1311use strum:: IntoEnumIterator ;
1412
1513fn bench_handshake_for_library < T > (
@@ -22,20 +20,34 @@ fn bench_handshake_for_library<T>(
2220 T :: Config : TlsBenchConfig ,
2321{
2422 let crypto_config = CryptoConfig :: new ( CipherSuite :: default ( ) , kx_group, sig_type) ;
23+ let client_config = & T :: Config :: make_config ( Mode :: Client , crypto_config, handshake_type) . unwrap ( ) ;
24+ let server_config = & T :: Config :: make_config ( Mode :: Server , crypto_config, handshake_type) . unwrap ( ) ;
2525
2626 // generate all harnesses (TlsConnPair structs) beforehand so that benchmarks
2727 // only include negotiation and not config/connection initialization
2828 bench_group. bench_function ( T :: name ( ) , |b| {
2929 b. iter_batched_ref (
30- || -> TlsConnPair < T , T > { TlsConnPair :: new_bench_pair ( crypto_config, handshake_type) . unwrap ( ) } ,
30+ || -> TlsConnPair < T , T > {
31+ if handshake_type == HandshakeType :: Resumption {
32+ // generate a session ticket to store on the config
33+ let mut pair = TlsConnPair :: < T , T > :: from_configs ( & client_config, & server_config) ;
34+ pair. handshake ( ) . unwrap ( ) ;
35+ pair. round_trip_transfer ( & mut [ 0 ] ) . unwrap ( ) ;
36+ }
37+ TlsConnPair :: from_configs ( client_config, server_config)
38+ } ,
3139 |conn_pair| {
3240 conn_pair. handshake ( ) . unwrap ( ) ;
3341 match handshake_type {
3442 HandshakeType :: ServerAuth | HandshakeType :: MutualAuth => assert ! ( !conn_pair. server. resumed_connection( ) ) ,
3543 HandshakeType :: Resumption => assert ! ( conn_pair. server. resumed_connection( ) ) ,
3644 }
3745 } ,
38- BatchSize :: SmallInput ,
46+ // Use "PerIteration" benchmarking, because of the way that session
47+ // ticket setup interacts with shared configs.
48+ // > In testing, the maximum measurement overhead from benchmarking
49+ // > with PerIteration is on the order of 350 nanoseconds
50+ BatchSize :: PerIteration ,
3951 )
4052 } ) ;
4153}
@@ -98,9 +110,6 @@ pub fn bench_handshake_sig_types(c: &mut Criterion) {
98110}
99111
100112criterion_group ! {
101- name = benches;
102- // profile 100 samples/sec
103- config = Criterion :: default ( ) . with_profiler( PProfProfiler :: new( PROFILER_FREQUENCY , Output :: Flamegraph ( None ) ) ) ;
104- targets = bench_handshake_types, bench_handshake_kx_groups, bench_handshake_sig_types
113+ benches, bench_handshake_types, bench_handshake_kx_groups, bench_handshake_sig_types
105114}
106115criterion_main ! ( benches) ;
0 commit comments