对python代码进行基准测试的一种简单方法
python-raptor的Python项目详细描述
猛禽
基准测试代码的简单方法。
如何使用
步骤1:首先,您需要为项目创建一个基准文件
"""to_benchmark.py"""#Add All Your Setupimportmath#Write Your Benchmarking Functionsdefbench_square_root():"""Name Your Function Starting With bench. Or Raptor Wont Detect It Also the function should not take any arguments"""returnmath.sqrt(25)defbench_multiply():return5**25
第2步:下载raptor.py
pip install python-raptor
然后,在终端中运行此命令
注意,-t参数接受一个整数,它告诉raptor多少次 是否每个基准测试功能都运行
raptor.py to_benchmark.py -t 10000
步骤3:查看输出。喂,喂!!!!!!!!!
输出
========== Bench Marking ===========
[bench_square_root] Took 0.0025385 Seconds For 10000 Run(s)
[bench_multiply] Took 0.0010813999999999997 Seconds For 10000 Run(s)
未来功能
- 我想添加一个历史记录,它可以显示您的程序有多快或多慢
- 我想添加彩色输出
- 我想添加更好的异常处理
内置
Raptor使用Timeit模块对代码进行基准测试
作者
罗山·吉格内斯·梅塔-sonicroshan122@gmail.com