ferranet 0.2.0

A modern, async-first, zero-copy datalink-layer (L2) networking library
Documentation
//! Criterion micro-benchmark of the zero-copy receive parse loop.
//!
//! Measures only the per-frame work `ferranet` does while walking a `TPACKET_V3` block (header
//! decode, VLAN check, packet-type classification, metadata construction) — no syscalls, no
//! kernel. It needs no privileges, so it belongs in CI as a regression guard on the hot path.
//!
//! ```sh
//! cargo bench --bench parse
//! # HTML report + plots: target/criterion/report/index.html
//! ```

use std::hint::black_box;

use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use ferranet::bench_support::{parse_v3_block, synth_v3_block};

fn parse(c: &mut Criterion) {
    let mut group = c.benchmark_group("parse_block");

    // A full RX block typically holds many frames; measure per-frame cost across frame sizes.
    const FRAMES: u32 = 256;
    for &size in &[64usize, 256, 1500] {
        let (buf, first, pkts) = synth_v3_block(FRAMES, size);

        // Report throughput two ways: frames/s (Elements) drives the headline number.
        group.throughput(Throughput::Elements(u64::from(FRAMES)));
        group.bench_with_input(BenchmarkId::new("frames", size), &size, |b, _| {
            b.iter(|| {
                let (frames, bytes) = parse_v3_block(black_box(&buf), first, pkts);
                black_box((frames, bytes));
            });
        });
    }

    group.finish();
}

criterion_group!(benches, parse);
criterion_main!(benches);