import time,os,psutil
pid=os.getpid()
m1=psutil.Process(pid).memory_info().rss
print('内存占用:%.2f MB'%(m1/1024/1024))
t1=time.time()
s=' '*2**20*100
t2=time.time()
m2=psutil.Process(pid).memory_info().rss
print("s=' '*2**20*100\n耗时:%f秒\n变量:%f MB"%(t2-t1,(m2-m1)/1024/1024))
t1=time.time()
l=[i for i in s]
t2=time.time()
m2=psutil.Process(pid)
Python 推导式的内存变化
最新推荐文章于 2024-06-10 12:09:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)