-
Notifications
You must be signed in to change notification settings - Fork 15
/
packet_decoding.rs
42 lines (36 loc) · 1.52 KB
/
packet_decoding.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#![feature(lazy_cell)]
use std::hint::black_box;
use std::sync::LazyLock as Lazy;
use bytes::Bytes;
use criterion::{criterion_group, criterion_main, Criterion};
use holo_ospf::packet::*;
use holo_ospf::version::Ospfv2;
use holo_utils::ip::AddressFamily;
static BYTES: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
0x02, 0x04, 0x00, 0x78, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x01,
0x40, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x31, 0x02, 0x01, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x02, 0x37, 0xf4, 0x00, 0x24,
0x01, 0x00, 0x00, 0x01, 0x0a, 0x00, 0x01, 0x00, 0xff, 0xff, 0xff, 0x00,
0x03, 0x00, 0x00, 0x0a, 0x00, 0x31, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x01, 0xd2, 0x7a, 0x00, 0x1c,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x02, 0x03,
0x0a, 0x00, 0x02, 0x00, 0x02, 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x01,
0xfa, 0x44, 0x00, 0x1c, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0a,
]
});
fn packet_decode(n: u64) {
for _ in 0..n {
let mut buf = Bytes::copy_from_slice(&BYTES);
let _ = Packet::<Ospfv2>::decode(AddressFamily::Ipv4, &mut buf, None)
.unwrap();
}
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Packet decode", |b| {
b.iter(|| packet_decode(black_box(10000)))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);