Files
deep2048/benchmark_tool.py
2025-07-23 07:04:10 +08:00

96 lines
2.7 KiB
Python
Raw Permalink 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.

#!/usr/bin/env python3
"""
Deep2048 基准测试工具启动器
快速启动性能基准测试,找到最优配置
"""
import sys
import os
from pathlib import Path
# 添加项目根目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
from tools.benchmark import QuickBenchmark
def main():
"""主函数"""
import argparse
parser = argparse.ArgumentParser(
description="Deep2048 性能基准测试工具",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
使用示例:
python benchmark_tool.py # 完整基准测试
python benchmark_tool.py --quick # 快速测试
python benchmark_tool.py -o results/my_test # 指定输出目录
"""
)
parser.add_argument(
"--output", "-o",
default="results/benchmark",
help="结果输出目录 (默认: results/benchmark)"
)
parser.add_argument(
"--quick",
action="store_true",
help="快速测试模式(仅测试线程性能)"
)
parser.add_argument(
"--threads", "-t",
type=int,
help="指定要测试的线程数(逗号分隔,如: 1,2,4,8"
)
args = parser.parse_args()
print("🚀 Deep2048 性能基准测试工具")
print("=" * 50)
try:
benchmark = QuickBenchmark(args.output)
if args.quick:
print("运行快速测试...")
thread_results = benchmark.test_thread_performance(100)
# 找到最佳配置
best_threads = max(thread_results.keys(),
key=lambda k: thread_results[k]['sims_per_sec'])
best_result = thread_results[best_threads]
print(f"\n🎯 快速推荐:")
print(f" 最优线程数: {best_threads}")
print(f" 预期速度: {best_result['sims_per_sec']:.1f} 模拟/秒")
print(f" CPU效率: {best_result['efficiency']:.1f} 模拟/秒/核心")
if best_threads > 1:
print(f" 多线程加速: {best_result['speedup']:.2f}x")
else:
print("运行完整基准测试...")
results = benchmark.run_full_benchmark()
benchmark.print_recommendations(results)
print(f"\n✅ 基准测试完成!")
except KeyboardInterrupt:
print("\n❌ 用户中断测试")
sys.exit(1)
except Exception as e:
print(f"\n❌ 测试过程中出现错误: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()