运行和分析基准测试的python模块

pyperf的Python项目详细描述


Latest release on the Python Cheeseshop (PyPI)Build status of pyperf on Travis CI

pythonpyperf模块是一个用于编写、运行和分析基准测试的工具包。

功能

  • 运行可靠基准的简单api
  • 自动校准时间预算的基准。
  • 生成多个工作进程。
  • 计算平均值和标准差。
  • 检测基准测试结果是否不稳定。
  • 存储基准测试结果的json格式。
  • 支持多个单位:秒、字节和整数。

用法

run a benchmark使用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 python3importpyperfrunner=pyperf.Runner()runner.timeit(name="sort a sorted list",stmt="sorted(s, key=f)",setup="f = lambda x: x; s = list(range(1000))")

有关timeit函数和 Runner类。运行脚本并将结果转储到名为 bench.json

$ python3 bench.py -o bench.json

analyze benchmark results使用pyperf stats命令:

$ python3 -m pyperf stats bench.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命令测试是否存在差异 意义重大。它支持多个基准测试套件(made 多个基准)

    $ python3 -m pyperf compare_to py2.json py3.json --table
    +-----------+---------+------------------------------+
    | Benchmark | py2     | py3                          |
    +===========+=========+==============================+
    | timeit    | 4.70 us | 4.22 us: 1.11x faster (-10%) |
    +-----------+---------+------------------------------+
    
  • pyperf system tune命令来优化系统以运行稳定的基准测试。

  • 自动收集计算机和基准上的元数据: 使用pyperf metadata命令显示它们,或者 pyperf collect_metadata手动收集它们的命令。

  • --track-memory--tracemalloc要跟踪的选项 基准的内存使用情况。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaJSonarray不会从SeekBar读取double   使用另一个类从Java中的2D数组打印用户输入   java ClassNotFoundException的原因   spring调用两个方法以返回Java中的不同页面   httpurlconnection Java禁止的代码错误,但浏览器错误(2)   java画布矩阵转换   java:在另一个java映射中使用“Map”作为值   java“未找到用于解密的证书”(Apache CXF,WSSecurity)   java如何查看JTable中选择的行   java在没有xmlwrappers的情况下重复xml元素序列集   java将垂直直方图打印到控制台   java Spring JDBCTemplate:构造不带特殊字符的JSON   java PayPal RestApi获取用户信息