当模块使用
import cProfile
import re
cProfile.run('re.compile("foo|bar")')
197 function calls (192 primitive calls) in 0.002 seconds
Ordered by: standard name
1 0.000 0.000 0.001 0.001 <string>:1(<module>)
1 0.000 0.000 0.001 0.001 re.py:212(compile)
1 0.000 0.000 0.001 0.001 re.py:268(_compile)
1 0.000 0.000 0.000 0.000 sre_compile.py:172(_compile_charset)
1 0.000 0.000 0.000 0.000 sre_compile.py:201(_optimize_charset)
4 0.000 0.000 0.000 0.000 sre_compile.py:25(_identityfunction)
3/1 0.000 0.000 0.000 0.000 sre_compile.py:33(_compile)
字段 | 解释 |
---|
ncalls | 调用次数 |
tottime | 函数耗费时间,不包含调用子函数的时间 |
percall | tottime/ncalls |
cumtime | 该函数包含子函数的总时间 |
percall | cumtime/primitive |
以脚本形式
python -m cProfile [-o 输出路径] [-s 排序字段(cumtime))] myscript.py