如何在 Python 中分析內存使用情況? - How do I profile memory usage in Python?

問題:

I've recently become interested in algorithms and have begun exploring them by writing a naive implementation and then optimizing it in various ways.我最近對算法產生了興趣,並開始通過編寫一個簡單的實現然後以各種方式對其進行優化來探索它們。

I'm already familiar with the standard Python module for profiling runtime (for most things I've found the timeit magic function in IPython to be sufficient), but I'm also interested in memory usage so I can explore those tradeoffs as well (eg the cost of caching a table of previously computed values versus recomputing them as needed).我已經熟悉用於分析運行時的標準 Python 模塊(對於大多數情況,我發現 IPython 中的 timeit 魔術函數就足夠了),但我也對內存使用感興趣,因此我也可以探索這些權衡(例如,緩存先前計算值的表與根據需要重新計算它們的成本)。 Is there a module that will profile the memory usage of a given function for me?是否有一個模塊可以爲我分析給定函數的內存使用情況?


解決方案:

參考一: https://stackoom.com/question/2JnE
參考二: How do I profile memory usage in Python?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章