---练习用---
作用:统计获取脚本运行时长和内存占用
需要安装psuti模块:pip install psutil
1
#
!python
2
3
import
time
4
import
psutil
5
import
os
6
7
def
show_info(start):
8 pid = os.getpid()
9 p = psutil.Process(pid)
10 info = p.memory_full_info()
11 memory = info.uss/1024
12return memory
1314def func():
1516print(‘function‘)
171819if__name__ == "__main__":
2021 first = time.time()
22 start = show_info(‘Begin‘)
2324 func()
2526 end = show_info(‘End‘)
27print(‘Memory cost :‘ + str(end-start) + ‘ KB‘)
28 final = time.time()
29print(‘Time cost :‘ + str(round(final-first,4)) + ‘s‘)
学习材料来源:
原文:https://www.cnblogs.com/shm30/p/15228097.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!