python内存分析
时间:2019-08-30 23:20:50
收藏:0
阅读:102
安装
首先安装memory_profiler和psutil
pip install memory_profiler
pip install psutil
- 在需要分析的函数前面添加装饰器@profile
@profile()
def call():
a = list()
for i in range(10000 * 100):
a .append(i)
运行call后的输出:
Line # Mem usage Increment Line Contents
================================================
283 40.1 MiB 40.1 MiB @profile
284 def call():
285 40.1 MiB 0.0 MiB a = list()
286 44.1 MiB 0.0 MiB for i in range(10000 * 10):
287 44.1 MiB 0.3 MiB a .append(i)
原文:https://www.cnblogs.com/bryant24/p/11437479.html
评论(0)