#!/usr/bin/env bash
set -euo pipefail

PYTHON=~/typeagent/.venv/bin/python
OUTDIR="$HOME/results/import"
mkdir -p "$OUTDIR"

echo "=== typeagent import benchmark ==="
echo ""

# E2E import time (direct venv to avoid uv run overhead)
hyperfine --warmup 5 --min-runs 30 --shell=none \
  --export-json "$OUTDIR/import.json" \
  "$PYTHON -c 'import typeagent'"

# Per-module breakdown
$PYTHON -X importtime -c 'import typeagent' 2>"$OUTDIR/importtime_raw.txt"
sort -t'|' -k1 -rn "$OUTDIR/importtime_raw.txt" | head -30 > "$OUTDIR/importtime_top30.txt"

echo ""
echo "Top 30 imports by self time:"
cat "$OUTDIR/importtime_top30.txt"
