python脚本的CPU使用率 [英] CPU usage of python script

查看:314
本文介绍了python脚本的CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检查简单脚本的CPU使用率?

Is it possible to check CPU usage of simple script ?

例如:如何获得打印100倍"hello world!"中的CPU使用率. ?

For example: How to get the CPU usage in % of printing 100 times "hello world!" ?

目前,我正在控制台中获取执行时间,方法是:

Currently I'm getting the execution time in the console, by:

time -p python script.py

推荐答案

您将需要psutil模块.

You'll need the psutil module.

import psutil
print(psutil.cpu_percent())

这篇关于python脚本的CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆