|
| 1 | +use criterion::{criterion_group, criterion_main, Criterion}; |
| 2 | +use sdp::SessionDescription; |
| 3 | +use std::io::Cursor; |
| 4 | + |
| 5 | +const CANONICAL_UNMARSHAL_SDP: &str = "v=0\r\n\ |
| 6 | +o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\r\n\ |
| 7 | +s=SDP Seminar\r\n\ |
| 8 | +i=A Seminar on the session description protocol\r\n\ |
| 9 | +u=http://www.example.com/seminars/sdp.pdf\r\n\ |
| 10 | + |
| 11 | +p=+1 617 555-6011\r\n\ |
| 12 | +c=IN IP4 224.2.17.12/127\r\n\ |
| 13 | +b=X-YZ:128\r\n\ |
| 14 | +b=AS:12345\r\n\ |
| 15 | +t=2873397496 2873404696\r\n\ |
| 16 | +t=3034423619 3042462419\r\n\ |
| 17 | +r=604800 3600 0 90000\r\n\ |
| 18 | +z=2882844526 -3600 2898848070 0\r\n\ |
| 19 | +k=prompt\r\n\ |
| 20 | +a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host\r\n\ |
| 21 | +a=recvonly\r\n\ |
| 22 | +m=audio 49170 RTP/AVP 0\r\n\ |
| 23 | +i=Vivamus a posuere nisl\r\n\ |
| 24 | +c=IN IP4 203.0.113.1\r\n\ |
| 25 | +b=X-YZ:128\r\n\ |
| 26 | +k=prompt\r\n\ |
| 27 | +a=sendrecv\r\n\ |
| 28 | +m=video 51372 RTP/AVP 99\r\n\ |
| 29 | +a=rtpmap:99 h263-1998/90000\r\n"; |
| 30 | + |
| 31 | +fn benchmark_sdp(c: &mut Criterion) { |
| 32 | + let mut reader = Cursor::new(CANONICAL_UNMARSHAL_SDP.as_bytes()); |
| 33 | + let sdp = SessionDescription::unmarshal(&mut reader).unwrap(); |
| 34 | + |
| 35 | + /////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | + c.bench_function("Benchmark Marshal", |b| { |
| 37 | + b.iter(|| { |
| 38 | + let _ = sdp.marshal(); |
| 39 | + }) |
| 40 | + }); |
| 41 | + |
| 42 | + c.bench_function("Benchmark Unmarshal ", |b| { |
| 43 | + b.iter(|| { |
| 44 | + let mut reader = Cursor::new(CANONICAL_UNMARSHAL_SDP.as_bytes()); |
| 45 | + let _ = SessionDescription::unmarshal(&mut reader).unwrap(); |
| 46 | + }) |
| 47 | + }); |
| 48 | +} |
| 49 | + |
| 50 | +criterion_group!(benches, benchmark_sdp); |
| 51 | +criterion_main!(benches); |
0 commit comments