Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python Popen对脚本进行基准测试?_Python_Process_Benchmarking_Popen - Fatal编程技术网

使用Python Popen对脚本进行基准测试?

使用Python Popen对脚本进行基准测试?,python,process,benchmarking,popen,Python,Process,Benchmarking,Popen,我有一个脚本(这是一个hadoop pig脚本到b precise),我想从中度量执行时间。我可能计划多次运行测试,并将平均/中间时间作为执行时间 由于手动启动脚本几次可能会非常麻烦,我想编写一个脚本来运行这些测试 使用Python的Popen启动一个执行脚本的新进程并测量进程运行的时间是否是一个好主意,比如: # start timer p = subprocess.Popen(...) stdout, stderr = p.communicate() # end timer 创建一个新的过

我有一个脚本(这是一个hadoop pig脚本到b precise),我想从中度量执行时间。我可能计划多次运行测试,并将平均/中间时间作为执行时间

由于手动启动脚本几次可能会非常麻烦,我想编写一个脚本来运行这些测试

使用Python的Popen启动一个执行脚本的新进程并测量进程运行的时间是否是一个好主意,比如:

# start timer
p = subprocess.Popen(...)
stdout, stderr = p.communicate()
# end timer
创建一个新的过程是否会使时间测量的结果发生偏差,或者这种方法可以吗?还有其他建议吗

最好的,
威尔

我也会使用
时间
实用程序:

time python foo.py

然后,您可以制作一个bash脚本来多次运行该脚本,记录每次运行所花费的时间。然后,只需使用shell实用程序或Python脚本对它们进行平均。

而不是while循环,只需使用
p.communicate()
等待进程完成即可。(或
p.wait()?p.Communication缓冲整个输出直到打印出来吗?有没有办法定期打印部分输出/刷新缓冲区?或者,在Linux上,您可以使用time命令对进程的运行量进行基准测试。例如,“time myprog”将运行myprog,并在最后告诉您它花费了多少时间。如果需要在Python中执行此操作,check可能会很有用。