运行和分析基准测试的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第三方库


热门话题
java如何编写带有连接的动态JPA查询?   子列表上的java分区列表,其中相邻子列表的第一个和最后一个元素相同   java限定符注释方法找不到作为配置类的bean   java同时抛出主异常和子类型,有合适的方法吗?   LString将是一个链表类,它模仿标准的JavaString和StringBuilder类   spring上下文关闭时java停止ConcurrentTaskScheduler   Java继承基类使用派生类方法   java Google的zxing(斑马线)条形码库的位矩阵不是它应该位于的位置   java使用springhateoas反序列化包含(_链接和_嵌入)的JSON   java破坏者如何使用环形缓冲区读取文件?   java在Android中获得用户的日常路线?   javajenkins:依赖于其他工件/项目的构建作业   java家庭替换应用程序/视图网格使用哪种布局?   java如何从签名证书创建信任库和密钥库?