python - python程序中多个片段的CPU时间计数
问题描述
我正在编写代码来计算程序的 CPU 时间。相关代码是这样的:
with open(script_path, "r") as src:
scr_contents = src.read()
proc = subprocess.run(["python", script_path], capture_output = True)
cup_time = time.process_time()
这个脚本给了我运行整个 scr_contents 程序的 CPU 时间。
现在,假设我在这个程序中有很多片段,并且我想获取每个片段的 CPU 时间,有什么方法或函数可用于这个 CPU 时间计数的目的?
解决方案
推荐阅读
- python - 以字符串形式python实现条件语句
- reactjs - 将状态参数传递给函数
- java - 向 ArrayList Java 添加不同大小的数组
- php - PHP foreach循环并将值添加到mysql表
- depth-first-search - 解决河内塔的最佳搜索算法?
- sql - 如何将 2 个 SQL 组合成一个 SQL
- ios - 如何使用 NSSecureCoding 和 NSKeyedArchiver 将一组类写入文档目录?
- python - 编写一个程序,询问用户在 1 到 12 之间的一个小时,以及他们想在未来多少小时
- python - TensorFlow 2 中 Densenet 密集块的 TypeError
- go - 如何在 GoLang 中找到 json.Unmarshalled() 对象的长度?