Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 643 Bytes

python_mem_monitor.md

File metadata and controls

40 lines (26 loc) · 643 Bytes

Python 内存测试

  • install psutil
import gc 
import os 
import psutil

def test(): 
    for i in range(10000000):
        pass


if __name__ == '__main__' :
    gc.collect()
    test()
    p = psutil.Process(os.getpid())
    mem =  p.memory_info() 
    print mem ,  mem.rss / 1024/1024  , "M used"
# range
pmem(rss=332668928L, vms=4710641664L, pfaults=82478, pageins=0) 317 M used

# xrange
pmem(rss=6696960L, vms=4385259520L, pfaults=2897, pageins=0) 6 M used