1- use bytes:: BytesMut ;
1+ use bytes:: { Bytes , BytesMut } ;
22use criterion:: { criterion_group, criterion_main, Criterion } ;
33use util:: Marshal ;
44use webrtc_srtp:: { context:: Context , protection_profile:: ProtectionProfile } ;
55
6+ const RAW_RTCP : Bytes = Bytes :: from_static ( & [
7+ 0x81 , 0xc8 , 0x00 , 0x0b , 0xca , 0xfe , 0xba , 0xbe , 0xab , 0xab , 0xab , 0xab , 0xab , 0xab , 0xab ,
8+ 0xab , 0xab , 0xab , 0xab , 0xab , 0xab , 0xab , 0xab , 0xab ,
9+ ] ) ;
10+
611fn benchmark_encrypt_rtp_aes_128_cm_hmac_sha1 ( c : & mut Criterion ) {
712 let mut ctx = Context :: new (
813 & vec ! [
@@ -20,7 +25,7 @@ fn benchmark_encrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
2025 pld. extend_from_slice ( & [ i as u8 ] ) ;
2126 }
2227
23- c. bench_function ( "Benchmark encrypt" , |b| {
28+ c. bench_function ( "Benchmark RTP encrypt" , |b| {
2429 let mut seq = 1 ;
2530 b. iter_batched (
2631 || {
@@ -58,7 +63,7 @@ fn benchmark_decrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
5863 None ,
5964 None ,
6065 )
61- . unwrap ( ) ;
66+ . unwrap ( ) ;
6267
6368 let mut ctx = Context :: new (
6469 & vec ! [
@@ -69,14 +74,14 @@ fn benchmark_decrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
6974 None ,
7075 None ,
7176 )
72- . unwrap ( ) ;
77+ . unwrap ( ) ;
7378
7479 let mut pld = BytesMut :: new ( ) ;
7580 for i in 0 ..1200 {
7681 pld. extend_from_slice ( & [ i as u8 ] ) ;
7782 }
7883
79- c. bench_function ( "Benchmark decrypt" , |b| {
84+ c. bench_function ( "Benchmark RTP decrypt" , |b| {
8085 let mut seq = 1 ;
8186 b. iter_batched (
8287 || {
@@ -96,15 +101,67 @@ fn benchmark_decrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
96101 seq += 1 ;
97102 setup_ctx. encrypt_rtp ( & pkt. marshal ( ) . unwrap ( ) ) . unwrap ( )
98103 } ,
99- |encrypted| {
100- ctx. decrypt_rtp ( & encrypted) . unwrap ( )
101- } ,
104+ |encrypted| ctx. decrypt_rtp ( & encrypted) . unwrap ( ) ,
102105 criterion:: BatchSize :: LargeInput ,
103106 ) ;
104107 } ) ;
105108}
106109
110+ fn benchmark_encrypt_rtcp_aes_128_cm_hmac_sha1 ( c : & mut Criterion ) {
111+ let mut ctx = Context :: new (
112+ & vec ! [
113+ 96 , 180 , 31 , 4 , 119 , 137 , 128 , 252 , 75 , 194 , 252 , 44 , 63 , 56 , 61 , 55 ,
114+ ] ,
115+ & vec ! [ 247 , 26 , 49 , 94 , 99 , 29 , 79 , 94 , 5 , 111 , 252 , 216 , 62 , 195 ] ,
116+ ProtectionProfile :: Aes128CmHmacSha1_80 ,
117+ None ,
118+ None ,
119+ )
120+ . unwrap ( ) ;
121+
122+ c. bench_function ( "Benchmark RTCP encrypt" , |b| {
123+ b. iter ( || {
124+ ctx. encrypt_rtcp ( & RAW_RTCP )
125+ . unwrap ( ) ;
126+ } ) ;
127+ } ) ;
128+ }
129+
130+ fn benchmark_decrypt_rtcp_aes_128_cm_hmac_sha1 ( c : & mut Criterion ) {
131+ let encrypted = Context :: new (
132+ & vec ! [
133+ 96 , 180 , 31 , 4 , 119 , 137 , 128 , 252 , 75 , 194 , 252 , 44 , 63 , 56 , 61 , 55 ,
134+ ] ,
135+ & vec ! [ 247 , 26 , 49 , 94 , 99 , 29 , 79 , 94 , 5 , 111 , 252 , 216 , 62 , 195 ] ,
136+ ProtectionProfile :: Aes128CmHmacSha1_80 ,
137+ None ,
138+ None ,
139+ )
140+ . unwrap ( )
141+ . encrypt_rtcp ( & RAW_RTCP )
142+ . unwrap ( ) ;
143+
144+ let mut ctx = Context :: new (
145+ & vec ! [
146+ 96 , 180 , 31 , 4 , 119 , 137 , 128 , 252 , 75 , 194 , 252 , 44 , 63 , 56 , 61 , 55 ,
147+ ] ,
148+ & vec ! [ 247 , 26 , 49 , 94 , 99 , 29 , 79 , 94 , 5 , 111 , 252 , 216 , 62 , 195 ] ,
149+ ProtectionProfile :: Aes128CmHmacSha1_80 ,
150+ None ,
151+ None ,
152+ )
153+ . unwrap ( ) ;
107154
155+ c. bench_function ( "Benchmark RTCP decrypt" , |b| {
156+ b. iter ( || ctx. decrypt_rtcp ( & encrypted) . unwrap ( ) ) ;
157+ } ) ;
158+ }
108159
109- criterion_group ! ( benches, benchmark_encrypt_rtp_aes_128_cm_hmac_sha1, benchmark_decrypt_rtp_aes_128_cm_hmac_sha1) ;
160+ criterion_group ! (
161+ benches,
162+ benchmark_encrypt_rtp_aes_128_cm_hmac_sha1,
163+ benchmark_decrypt_rtp_aes_128_cm_hmac_sha1,
164+ benchmark_encrypt_rtcp_aes_128_cm_hmac_sha1,
165+ benchmark_decrypt_rtcp_aes_128_cm_hmac_sha1
166+ ) ;
110167criterion_main ! ( benches) ;
0 commit comments