Python脚本的性能分析

本文最后更新于2015年3月7日,已超过 1 年没有更新,如果文章内容失效,还请反馈给我,谢谢!

搜索关键字:

http://search.aol.com/aol/search?q=python+running+performance+analysis

参考结论:

Python includes a profiler called cProfile. It not only gives the total running time, but also times each function separately, and tells you how many times each function was called, making it easy to determine where you should make optimizations.

You can call it from within your code, or from the interpreter, like this:

Even more usefully, you can invoke the cProfile when running a script:

To make it even easier, I made a little batch file called ‘profile.bat’:

So all I have to do is run:

And I get this:

EDIT: Updated link to a good video resource from PyCon 2013: http://lanyrd.com/2013/pycon/scdywg/

参考链接:

==

如何检测Python脚本可能存在的内存泄漏问题?
搜索关键字:

http://search.aol.com/aol/search?q=python+memory+leakage

参考链接:

==

在Python中测试某段代码的执行时间
搜索关键字:
参考链接:
测试例子:
参考结论:

Given test.py:

run timeit like this:

The following example shows how the Command-Line Interface can be used to compare three different expressions:

This can be achieved from the Python Interface with:

Note however that timeit will automatically determine the number of repetitions only when the command-line interface is used. In the Examples section you can find more advanced examples.

https://docs.python.org/2/library/timeit.html

####

####

声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!
https://ixyzero.com/blog/archives/1978.html

《Python脚本的性能分析》上有1条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注