如何在VSCode中显示程序占用的时间和空间



我使用VSCode已经一年多了。几乎每天我都在网上搜索显示程序所花费的时间(速度(和空间(执行过程中(的方法。这些信息非常重要。但不幸的是,我没有找到(或错过(显示这些指标的方法。VSCode使用起来很酷,重量轻等等,但这些度量在其他一些IDE(如代码块(中默认可见。在我阅读的许多文章中,我错过了一些扩展或设置。如果有人能在这里帮我,我将不胜感激。

提前感谢

if __name__ == "__main__":
''' 
Example code shows to display 
the Time and Space taking of the program(creating N_gram language model)
'''
import os, psutil, time
start = time.time()
m = create_ngram_model(3, '/content/train_corpus.txt')  # Replace withyour custom function
process = psutil.Process(os.getpid())
print('Memory usage in Mega Bytes: ', process.memory_info().rss/(1024**2))  # in bytes 
print(f'Time Taken: {time.time() - start}')

您可以在任何函数中添加此psutil.Process(os.getpid())(在main线程中查看程序的整个内存使用情况(,您希望在运行时通过process.memory_info().rss查看状态内存使用情况:0.5774040222167969。还要检查此代码以了解程序运行时。

最新更新