#![allow(
missing_docs,
clippy::doc_markdown,
clippy::expect_used,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use matter_codec::{Tag, TlvWriter};
use matter_interaction::parse_report_data;
fn build_report(n_attrs: usize, val_len: usize) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous).expect("msg");
w.start_array(Tag::Context(1)).expect("AttributeReports"); let data = vec![0xCDu8; val_len];
for i in 0..n_attrs {
w.start_structure(Tag::Anonymous).expect("IB"); w.start_structure(Tag::Context(1)).expect("AttributeData"); w.start_list(Tag::Context(1)).expect("Path"); w.put_uint(Tag::Context(2), 1).expect("endpoint"); w.put_uint(Tag::Context(3), 0x0006).expect("cluster"); w.put_uint(Tag::Context(4), i as u64).expect("attribute"); w.end_container().expect("end path");
w.put_bytes(Tag::Context(2), &data).expect("Data"); w.end_container().expect("end AttributeData");
w.end_container().expect("end IB");
}
w.end_container().expect("end array");
w.end_container().expect("end msg");
buf
}
fn bench_parse(c: &mut Criterion) {
let report = build_report(170, 64);
c.bench_function("parse_report_data/170attr_64B", |b| {
b.iter(|| black_box(parse_report_data(black_box(&report)).expect("parse")));
});
let small = build_report(20, 4);
c.bench_function("parse_report_data/20attr_4B", |b| {
b.iter(|| black_box(parse_report_data(black_box(&small)).expect("parse")));
});
}
criterion_group!(benches, bench_parse);
criterion_main!(benches);