#!/usr/bin/env bash
# Run ferranet's Criterion benchmarks and generate the HTML report + plots.
#
# The throughput bench needs CAP_NET_RAW/CAP_NET_ADMIN; we build outside the network namespace
# (which has no network for the registry/cache) and run inside it via `unshare`.
#
# Criterion writes statistics, an HTML report, and SVG plots to target/criterion/.
set -euo pipefail
cd "$(dirname "$0")/.."

echo "== parse micro-bench (no privileges) =="
cargo bench --bench parse

echo
echo "== throughput + fanout (veth, in a user+net namespace) =="
cargo bench --bench throughput --no-run >/dev/null
unshare --user --map-root-user --net env RUSTC_WRAPPER= cargo bench --bench throughput

echo
echo "Report: target/criterion/report/index.html"
echo "Plots:  target/criterion/<group>/<bench>/report/*.svg"
