#! /usr/bin/env python # encoding=utf8 import profile def func1(): for i in range(1000): pass def func2(): for i in range(1000): func1() profile.run("func2()")

输出:

python  profile性能分析

其中输出每列的具体解释如下:

●ncalls:表示函数调用的次数;

●tottime:表示指定函数的总的运行时间,除掉函数中调用子函数的运行时间;

●percall:(第一个 percall)等于 tottime/ncalls;

●cumtime:表示该函数及其所有子函数的调用运行的时间,即函数开始调用到返回的时间;

●percall:(第二个 percall)即函数运行一次的平均时间,等于 cumtime/ncalls;

●filename:lineno(function):每个函数调用的具体信息;

如果需要将输出以日志的形式保存,只需要在调用的时候加入另外一个参数。如 profile.run(“profileTest()”,”testprof”)。

 

相关文章:

  • 2021-12-12
  • 2021-09-16
  • 2021-11-02
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-08-22
  • 2021-07-20
  • 2021-06-08
  • 2022-02-08
  • 2021-06-13
  • 2021-07-30
  • 2022-01-17
相关资源
相似解决方案