python內存分析

安裝
首先安裝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)
在學習過程中有什麼不懂得可以加
我的python學習交流扣扣qun,688244617
羣裏有不錯的學習教程、開發工具與電子書籍。
與你分享python企業當下人才需求及怎麼從零基礎學習好python,和學習什麼內容。

運行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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章