#!/bin/bash
# run_latency.sh - Run sender-side completion latency benchmarks for key data sizes.
#
# Output: CSV with sender-side completion latency in microseconds.
# Usage: ./run_latency.sh
#
# Part of: https://2b.ai post/linux/zero-copy-dirty-truth

set -e

WARMUP=2
RUN=5
PORT=9400

SIZES="4096 65536 1048576"
METHODS="readwrite sendfile splice iouring_zc"

echo "method,data_size,p50_us,p99_us,p999_us,max_us,samples"

for SIZE in $SIZES; do
  for METHOD in $METHODS; do
    PORT=$((PORT + 1))
    ./bench_latency "$METHOD" "$SIZE" "$PORT" "$WARMUP" "$RUN" 2>/dev/null
    sleep 1
  done
done
