#!/usr/bin/env bash
# Measure startup time for common library sourcing and representative scripts
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"

measure() {
  local label="$1"; shift
  local cmd=("$@")
  local start end ms
  start=$(date +%s%3N)
  "${cmd[@]}" >/dev/null 2>&1 || true
  end=$(date +%s%3N)
  ms=$((end-start))
  printf "%s: %d ms\n" "$label" "$ms"
}

echo "Startup timing (ms):"
measure "source lib/init.sh" bash -lc "SCRIPT_DIR='$ROOT_DIR/scripts/deployment' source '$ROOT_DIR/scripts/lib/init.sh'"
measure "calculate-costs --help" bash -lc "SCRIPT_DIR='$ROOT_DIR/scripts/deployment' source '$ROOT_DIR/scripts/lib/init.sh'; '$ROOT_DIR/scripts/deployment/calculate-costs-consolidated.sh' --help"
measure "deploy-parallel --help" bash -lc "SCRIPT_DIR='$ROOT_DIR/scripts/deployment' source '$ROOT_DIR/scripts/lib/init.sh'; '$ROOT_DIR/scripts/deployment/deploy-parallel-consolidated.sh' --help"
measure "list-all-resources --help" bash -lc "SCRIPT_DIR='$ROOT_DIR/scripts/azure' source '$ROOT_DIR/scripts/lib/init.sh'; '$ROOT_DIR/scripts/azure/list-all-resources.sh' --help"
echo "Done."
