Skip to content

Commit bf65b67

Browse files
logist322rainliu
authored andcommitted
Bench
1 parent 76cc393 commit bf65b67

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

srtp/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ aead = { version = "0.4.3", features = ["std"] }
3333
aes-gcm = { version = "0.10.1", features = ["std"] }
3434

3535
[dev-dependencies]
36+
criterion = { version = "0.4.0", features = ["async_futures"] }
3637
tokio-test = "0.4.0" # must match the min version of the `tokio` crate above
3738
lazy_static = "1.4.0"
39+
40+
[[bench]]
41+
name = "srtp_bench"
42+
harness = false

srtp/benches/srtp_bench.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use bytes::Bytes;
2+
use criterion::{criterion_group, criterion_main, Criterion};
3+
use util::Marshal;
4+
use webrtc_srtp::{context::Context, protection_profile::ProtectionProfile};
5+
6+
fn benchmark_buffer(c: &mut Criterion) {
7+
let mut ctx = Context::new(
8+
&vec![0; 16],
9+
&vec![0; 14],
10+
ProtectionProfile::Aes128CmHmacSha1_80,
11+
None,
12+
None,
13+
).unwrap();
14+
let pkt = rtp::packet::Packet {
15+
header: rtp::header::Header {
16+
sequence_number: 322,
17+
..Default::default()
18+
},
19+
payload: Bytes::from_static(&[0x00, 0x01, 0x02, 0x03, 0x04, 0x05]),
20+
};
21+
let pkt_raw = pkt.marshal().unwrap();
22+
23+
c.bench_function("Benchmark context ", |b| {
24+
b.iter(|| {
25+
ctx.encrypt_rtp(&pkt_raw).unwrap();
26+
});
27+
});
28+
}
29+
30+
criterion_group!(benches, benchmark_buffer);
31+
criterion_main!(benches);

0 commit comments

Comments
 (0)