我想提高Python脚本的性能,并一直cProfile用于生成性能报告:
python -m cProfile -o chrX.prof ./bgchr.py ...args...
Run Code Online (Sandbox Code Playgroud)
我chrX.prof用Python 打开了这个文件pstats并打印出统计信息:
Python 2.7 (r27:82500, Oct 5 2010, 00:24:22)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pstats
>>> p = pstats.Stats('chrX.prof')
>>> p.sort_stats('name')
>>> p.print_stats()
Sun Oct 10 00:37:30 2010 chrX.prof
8760583 function calls in 13.780 CPU seconds
Ordered by: function name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 {_locale.setlocale} …Run Code Online (Sandbox Code Playgroud)