Files
monitor/backend/test_performance.sh
2025-12-07 18:15:50 +08:00

33 lines
891 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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"