Python 使用 memory_profiler 分析程序内存占用情况

Python 使用 memory_profiler 分析程序内存占用情况

确保安装好相关组件

from memory_profiler import profile
@profile
def test1():
    c = []
    a = [1, 2, 3] * (2 ** 20)
    b = [1] * (2 ** 20)
    c.extend(a)
    c.extend(b)
    del b
    del c

if __name__ == "__main__":
    test1()

在这里插入图片描述

Mem usage 为当前总内存 Increment 为增加的内存

参考http://wxnacy.com/2019/05/05/python-memory-profiler/

你可能感兴趣的:(Python,python)