Python - Debug + Profile
pdb
pdb 是 Python 自带的调试库,为 Python 程序提供交互式的源代码调试功能,是命令行版本的 IDE 断点调试器
| Instruction | Desc |
|---|---|
| p | |
| n | next - step over |
| l | list - show source code context |
| s | step into |
| r | stop out - 继续执行,直到当前函数完成后返回 |
| `b [ ([filename:]lineno | function) [, condition] ]` |
| c | continue - 一直执行程序,直到遇到下一个断点 |
step into -
--Call--+--Return--
cProfile
瓶颈在于 fib 函数
| Item | Desc |
|---|---|
| ncalls | 相应代码/函数被调用的次数 |
| tottime | 相应代码/函数总共执行所需的时间(不包括它调用其它代码/函数的执行时间) |
| tottime percall | tottime / ncalls |
| cumtime | 相应代码/函数总共执行所需的时间(包括它调用其它代码/函数的执行时间) |
| cumtime percall | cumtime / ncalls |
| filename:lineno(function) | 相应代码/函数位置 |
通过字典保存计算过的 fib 结果
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.















