更准确的计时器,用于测量来自 Python 的外部.exe运行时
More accurate timer for measuring external .exe runtime from Python?
我正在尝试使用Python从编译C++exe中获取返回值(同时对它们进行计时)。
这是我的蟒蛇代码
import subprocess
import time
info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE
t1 = time.clock()
h = subprocess.Popen([r"C:UsersMyNameDesktoptest.exe"], startupinfo=info)
h.communicate()
t2 = time.clock()-t1
print "Return Code:", h.returncode
print "Duration:", t2
这是测试的内容.cpp:
int main(){
return 1234;
}
这是蟒蛇的输出
Return Code: 1234
Duration: 0.0438238265388
我觉得 43+ 毫秒太长且不准确。有没有更好的方法?
我还建议从程序本身测量时间C++如果您仍然有兴趣在 Python 程序中获取时间,您可以返回从C++程序计算的时间,这应该是非常准确的。同样正如其他人建议的那样,平均多次运行。
相关文章:
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- Pybind11:将元组列表从Python传递到C++
- 如何在c++中使用引用实现类似python的行为
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 递归列出所有目录中的C++与Python与Ruby的性能
- IPC使用多个管道和分支进程来运行Python程序
- 从python中调用C++函数并获取返回值
- Python 3.7 和 excess_args 的 SWIG 问题
- 在函数内部的声明中初始化数组,并在外部使用它
- Python中的for循环与C++有何不同
- 使外部项目可用于find_package CMake
- Python 3.8:运行外部C++代码:无法导入模块
- 使用 Boost.Python 修复未解析的外部符号
- 未解析的外部符号构建 Python 模块
- 更准确的计时器,用于测量来自 Python 的外部.exe运行时
- C++中的Python:未解析的外部
- PyDev外部调试与新的python类型定义
- Qt调用外部Python脚本
- 调用一个外部C++函数,Memory Leaks:将在完成Python脚本后清理所有分配的内存
- Boost::带有函数模板的Python类:如何从外部添加实例