chore(bench): 扩展 Makefile 基准测试命令

- bench 目标输出到 bench-results.txt,count=5 采样
- 添加 bench-regression 目标,使用阈值配置检测回归

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-04-29 10:33:15 +08:00
parent 3c1aed791f
commit 7da9ffcb6b

View File

@ -210,10 +210,10 @@ act-unit:
exit 1; \
fi
# 运行基准测试
# 运行基准测试(输出到文件)
bench:
@echo "Running benchmarks..."
go test -bench=. -benchmem ./...
go test -bench=. -benchmem -count=5 ./... 2>&1 | tee bench-results.txt
# 运行基准测试统计模式10次采样
bench-stat:
@ -416,3 +416,20 @@ help:
@echo " make install - Install to GOPATH/bin"
@echo " make clean - Clean build artifacts"
@echo ""
# 回归检测(使用阈值配置文件)
bench-regression:
@echo "Detecting performance regressions with thresholds..."
@if [ ! -f .benchmark-thresholds.yaml ]; then \
echo "阈值配置文件不存在: .benchmark-thresholds.yaml"; \
exit 1; \
fi
@if [ -f bench-old.txt ] && [ -f bench-new.txt ]; then \
benchstat bench-old.txt bench-new.txt | python3 scripts/check_regression.py - --config .benchmark-thresholds.yaml; \
elif [ -f benchmark-baseline.txt ] && [ -f benchmark-current.txt ]; then \
benchstat benchmark-baseline.txt benchmark-current.txt | python3 scripts/check_regression.py - --config .benchmark-thresholds.yaml; \
else \
echo "需要 bench-old.txt 和 bench-new.txt 或 baseline/current 文件"; \
echo "运行: make bench-stat && mv benchmark-current.txt bench-old.txt && make bench-stat && mv benchmark-current.txt bench-new.txt"; \
exit 1; \
fi