Files
digit-cracker/scripts/run_benchmark_quick.sh
2025-10-30 16:31:47 +08:00

72 lines
3.3 KiB
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
# 快速并发性能测试(较小规模,适合快速验证)
echo "================================================================================"
echo "YOLO 数字识别 - 快速并发测试"
echo "================================================================================"
echo ""
RESULT_DIR="results/benchmark_quick"
mkdir -p "$RESULT_DIR"
IMAGES_PER_USER=10
USER_COUNTS=(1 3 5 8)
echo "📋 测试配置:"
echo " - 每用户图片数: $IMAGES_PER_USER"
echo " - 测试并发级别: ${USER_COUNTS[@]}"
echo ""
for users in "${USER_COUNTS[@]}"; do
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 测试: ${users} 个并发用户 × ${IMAGES_PER_USER} 张图片"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
python scripts/benchmark_concurrent.py \
--users "$users" \
--images-per-user "$IMAGES_PER_USER" \
--output "$RESULT_DIR/benchmark_${users}users.txt"
echo ""
done
# 生成摘要
SUMMARY_FILE="$RESULT_DIR/summary.txt"
{
echo "================================================================================"
echo "YOLO 数字识别 - 快速并发测试摘要"
echo "================================================================================"
echo ""
echo "测试时间: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
echo "性能对比:"
echo ""
printf "%-12s | %-10s | %-12s | %-12s | %-15s\n" \
"并发用户" "总图片" "总耗时(s)" "QPS" "平均响应(s)"
echo "-------------+------------+--------------+--------------+----------------"
} > "$SUMMARY_FILE"
for users in "${USER_COUNTS[@]}"; do
json_file="$RESULT_DIR/benchmark_${users}users.json"
if [ -f "$json_file" ]; then
total_images=$(python3 -c "import json; print(json.load(open('$json_file'))['summary']['total_images'])")
total_time=$(python3 -c "import json; print(f\"{json.load(open('$json_file'))['summary']['total_time']:.2f}\")")
qps=$(python3 -c "import json; print(f\"{json.load(open('$json_file'))['summary']['qps']:.2f}\")")
avg_time=$(python3 -c "import json; d=json.load(open('$json_file')); times=[r['time'] for u in d['users'] for r in u['results']]; print(f\"{sum(times)/len(times):.3f}\")")
printf "%-12d | %-10d | %-12s | %-12s | %-15s\n" \
"$users" "$total_images" "$total_time" "$qps" "$avg_time" >> "$SUMMARY_FILE"
fi
done
echo "" >> "$SUMMARY_FILE"
echo "================================================================================" >> "$SUMMARY_FILE"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
cat "$SUMMARY_FILE"
echo ""
echo "✅ 快速测试完成!详细报告: $RESULT_DIR/"
echo "================================================================================"