33 lines
891 B
Bash
Executable File
33 lines
891 B
Bash
Executable File
#!/bin/bash
|
||
|
||
# 测试API性能的脚本
|
||
API_URL="http://localhost:8080/api/metrics/hardware?device_id=device-1764692967636"
|
||
REQUEST_COUNT=10
|
||
|
||
echo "Starting performance test for $API_URL"
|
||
echo "Sending $REQUEST_COUNT requests..."
|
||
|
||
# 初始化总时间
|
||
total_time=0
|
||
|
||
# 发送请求并测量时间
|
||
for ((i=1; i<=$REQUEST_COUNT; i++)); do
|
||
# 使用curl测量响应时间,-w参数定义输出格式
|
||
time=$(curl -o /dev/null -s -w "%{time_total}\n" "$API_URL")
|
||
|
||
# 累加时间
|
||
total_time=$(echo "$total_time + $time" | bc)
|
||
|
||
# 打印当前请求的响应时间
|
||
echo "Request $i: $time seconds"
|
||
done
|
||
|
||
# 计算平均响应时间
|
||
average_time=$(echo "scale=6; $total_time / $REQUEST_COUNT" | bc)
|
||
|
||
echo ""
|
||
echo "Performance Test Results:"
|
||
echo "Total Requests: $REQUEST_COUNT"
|
||
echo "Total Time: $total_time seconds"
|
||
echo "Average Response Time: $average_time seconds"
|