ai-gateway/bin/time_test.sh

39 lines
1.1 KiB
Bash
Raw Normal View History

2023-06-22 11:14:31 +00:00
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: time_test.sh <domain> <key> <count>"
exit 1
fi
domain=$1
key=$2
count=$3
total_time=0
2023-06-22 11:25:27 +00:00
times=()
2023-06-22 11:14:31 +00:00
for ((i=1; i<=count; i++)); do
result=$(curl -o /dev/null -s -w "%{http_code} %{time_total}\\n" \
2023-06-22 11:14:31 +00:00
https://"$domain"/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $key" \
-d '{"messages": [{"content": "echo hi", "role": "user"}], "model": "gpt-3.5-turbo", "stream": false, "max_tokens": 1}')
http_code=$(echo "$result" | awk '{print $1}')
time=$(echo "$result" | awk '{print $2}')
echo "HTTP status code: $http_code, Time taken: $time"
total_time=$(bc <<< "$total_time + $time")
times+=("$time")
2023-06-22 11:14:31 +00:00
done
2023-06-22 11:25:27 +00:00
average_time=$(echo "scale=4; $total_time / $count" | bc)
2023-06-22 11:14:31 +00:00
2023-06-22 11:25:27 +00:00
sum_of_squares=0
for time in "${times[@]}"; do
difference=$(echo "scale=4; $time - $average_time" | bc)
square=$(echo "scale=4; $difference * $difference" | bc)
sum_of_squares=$(echo "scale=4; $sum_of_squares + $square" | bc)
done
standard_deviation=$(echo "scale=4; sqrt($sum_of_squares / $count)" | bc)
echo "Average time: $average_time±$standard_deviation"