#![allow(missing_docs)]
use criterion::{Criterion, criterion_group, criterion_main};
use std::net::Ipv4Addr;
use toe_beans::v4::*;
fn criterion_benchmark(c: &mut Criterion) {
let message = Message {
op: Ops::Request,
htype: HTypes::Ethernet,
hlen: 6,
hops: 1,
xid: 1,
secs: 1,
flags: Flags { broadcast: false },
ciaddr: Ipv4Addr::new(1, 1, 1, 1),
yiaddr: Ipv4Addr::new(1, 1, 1, 1),
siaddr: Ipv4Addr::new(1, 1, 1, 1),
giaddr: Ipv4Addr::new(1, 1, 1, 1),
chaddr: [3; 16],
sname: SName::new(c"000000000000000000000000000000000000000000000000000000000000000").unwrap(),
file: File::new(c"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@").unwrap(),
magic: [99, 130, 83, 99],
options: vec![MessageOptions::MessageType(MessageTypes::Discover), MessageOptions::T1(TimeOption::new(1000)), MessageOptions::T2(TimeOption::new(2000)), MessageOptions::LeaseTime(TimeOption::new(12345)), MessageOptions::RapidCommit, MessageOptions::RequestedIp(AddressOption::new(Ipv4Addr::new(127, 0, 0, 1))), MessageOptions::ServerIdentifier(AddressOption::new(Ipv4Addr::new(127, 0, 0, 1))), MessageOptions::Pad].into(),
};
c.bench_function("benchmark to_bytes (many options)", |b| {
b.iter(|| message.to_bytes())
});
let message_small = Message {
op: Ops::Request,
htype: HTypes::Ethernet,
hlen: 6,
hops: 1,
xid: 1,
secs: 1,
flags: Flags { broadcast: false },
ciaddr: Ipv4Addr::new(1, 1, 1, 1),
yiaddr: Ipv4Addr::new(1, 1, 1, 1),
siaddr: Ipv4Addr::new(1, 1, 1, 1),
giaddr: Ipv4Addr::new(1, 1, 1, 1),
chaddr: [3; 16],
sname: SName::new(c"000000000000000000000000000000000000000000000000000000000000000").unwrap(),
file: File::new(c"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@").unwrap(),
magic: [99, 130, 83, 99],
options: vec![MessageOptions::Pad].into(),
};
c.bench_function("benchmark to_bytes (few options)", |b| {
b.iter(|| message_small.to_bytes())
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);