开发者

How should I account for subprocess.Popen() overhead when timing in python?

more-intelligent-members-of-the-coding-community-than-I! I have a python question for you all... :)

I am trying to optimize a python script that is (among other things) returning the wall-clock time a subprocess took execute and terminate. I think I'm close with something like this.

startTime = time.time()
process = subprocess.Popen(['process', 'to', 'test'])
process.wait()
endTime = time.time()
wallTime = endTime - startTime

However, I am concerned that the overhead in subprocess.Popen() is inflating my results on older and exotic platforms. My first inclination is to somehow time the overhead caused by subprocess.Popen() by running a simple innocuous command. Such as the following on linux.

startTime = time.time()
process = subprocess.Popen(['touch', '/tmp/foo'])
process.wait()
endTime = time.time()
overheadWallTime = endTime - startTime

Or the following on windows.

startTime = 开发者_JAVA技巧time.time()
process = subprocess.Popen(['type', 'NUL', '>', 'tmp'])
process.wait()
endTime = time.time()
overheadWallTime = endTime - startTime

So, how should I account for subprocess.Popen() overhead when timing in python?

Or, what is an innocuous way to sample the overhead from subprocess.Popen()?

Or, maybe there's something I haven't considered yet?

The caveat is that the solution must be reasonably cross-platform.


Welcome to batteries included.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜