Python模块,用于运行和分析基准测试
项目描述
Python模块 pyperf 是一个用于编写、运行和分析基准测试的工具包。
功能
运行可靠基准测试的简单API
自动校准基准测试以适应时间预算。
启动多个工作进程。
计算平均值和标准差。
检测基准结果是否不稳定。
使用JSON格式存储基准结果。
支持多个单位:秒、字节和整数。
用法
要运行基准测试,使用 pyperf timeit 命令(结果写入 bench.json)
$ python3 -m pyperf timeit '[1,2]*1000' -o bench.json ..................... Mean +- std dev: 4.22 us +- 0.08 us
或者编写一个基准测试脚本 bench.py
#!/usr/bin/env python3
import pyperf
runner = pyperf.Runner()
runner.timeit(name="sort a sorted list",
stmt="sorted(s, key=f)",
setup="f = lambda x: x; s = list(range(1000))")
查看 API文档 以获取有关 timeit 函数和 Runner 类的详细信息。要运行脚本并将结果输出到名为 bench.json 的文件中
$ python3 bench.py -o bench.json
要分析基准结果,使用 pyperf stats 命令
$ python3 -m pyperf stats telco.json Total duration: 29.2 sec Start date: 2016-10-21 03:14:19 End date: 2016-10-21 03:14:53 Raw value minimum: 177 ms Raw value maximum: 183 ms Number of calibration run: 1 Number of run with values: 40 Total number of run: 41 Number of warmup per run: 1 Number of value per run: 3 Loop iterations per value: 8 Total number of values: 120 Minimum: 22.1 ms Median +- MAD: 22.5 ms +- 0.1 ms Mean +- std dev: 22.5 ms +- 0.2 ms Maximum: 22.9 ms 0th percentile: 22.1 ms (-2% of the mean) -- minimum 5th percentile: 22.3 ms (-1% of the mean) 25th percentile: 22.4 ms (-1% of the mean) -- Q1 50th percentile: 22.5 ms (-0% of the mean) -- median 75th percentile: 22.7 ms (+1% of the mean) -- Q3 95th percentile: 22.9 ms (+2% of the mean) 100th percentile: 22.9 ms (+2% of the mean) -- maximum Number of outlier (out of 22.0 ms..23.0 ms): 0
还有
pyperf compare_to 命令用于测试差异是否显著。它支持多个基准测试套件(由多个基准组成)之间的比较
$ python3 -m pyperf compare_to --table mult_list_py36.json mult_list_py37.json mult_list_py38.json +----------------+----------------+-----------------------+-----------------------+ | Benchmark | mult_list_py36 | mult_list_py37 | mult_list_py38 | +================+================+=======================+=======================+ | [1]*1000 | 2.13 us | 2.09 us: 1.02x faster | not significant | +----------------+----------------+-----------------------+-----------------------+ | [1,2]*1000 | 3.70 us | 5.28 us: 1.42x slower | 3.18 us: 1.16x faster | +----------------+----------------+-----------------------+-----------------------+ | [1,2,3]*1000 | 4.61 us | 6.05 us: 1.31x slower | 4.17 us: 1.11x faster | +----------------+----------------+-----------------------+-----------------------+ | Geometric mean | (ref) | 1.22x slower | 1.09x faster | +----------------+----------------+-----------------------+-----------------------+
pyperf system tune 命令用于调整系统以运行稳定的基准测试。
自动收集计算机和基准测试的元数据:使用 pyperf metadata 命令显示它们,或使用 pyperf collect_metadata 命令手动收集它们。
--track-memory 和 --tracemalloc 选项用于跟踪基准测试的内存使用情况。
快速链接
在Python 3上安装pyperf的命令
python3 -m pip install pyperf
pyperf需要Python 3.7或更高版本。
Python 2.7用户可以使用pyperf 1.7.1,这是与Python 2.7兼容的最后一个版本。
pyperf在MIT许可下分发。
pyperf项目受PSF行为准则的约束。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分发
pyperf-2.8.0.tar.gz (225.2 kB 查看哈希值)
构建分发
pyperf-2.8.0-py3-none-any.whl (142.5 kB 查看哈希值)
关闭
pyperf-2.8.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b30a20465819daf102b6543b512f6799a5a879ff2a123981e6cd732d0e6a7a79 |
|
MD5 | aac40171c00dd88742ffc2f339a7dc6a |
|
BLAKE2b-256 | 022a758b3c4cc9843bd385bc595b777345fbf4cd00733b7830cdff43e30002c0 |