Python分析(高级编程三)

调试和性能分析

用 pdb 进行代码调试

pdb常用方法

p (print)打印
n (next)下一步
s (step)进入方法内部
l (list)获取上下文

PDB官方文档


用 cProfile 进行性能分析

打印参数介绍
  • ncalls,是指相应代码 / 函数被调用的次数
  • tottime,是指对应代码 / 函数总共执行所需要的时间(注意,并不包括它调用的其他代码 / 函数的执行时间)
  • tottime percall,就是上述两者相除的结果,也就是tottime / ncalls
  • cumtime,则是指对应代码 / 函数总共执行所需要的时间,这里包括了它调用的其他代码 / 函数的执行时间
  • cumtime percall,则是 cumtime 和 ncalls 相除的平均结果。

You May Also Like

Comments

Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">