time_test.sh 589 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. if [ $# -ne 3 ]; then
  3. echo "Usage: time_test.sh <domain> <key> <count>"
  4. exit 1
  5. fi
  6. domain=$1
  7. key=$2
  8. count=$3
  9. total_time=0
  10. for ((i=1; i<=count; i++)); do
  11. result=$(curl -o /dev/null -s -w %{time_total}\\n \
  12. https://"$domain"/v1/chat/completions \
  13. -H "Content-Type: application/json" \
  14. -H "Authorization: Bearer $key" \
  15. -d '{"prompt": "hi!", "max_tokens": 1}')
  16. echo "$result"
  17. total_time=$(echo "$total_time + $result" | bc)
  18. done
  19. average_time=$(echo "scale=3; $total_time / $count" | bc)
  20. echo "Average time: $average_time"