Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I account for subprocess.Popen() overhead when timing in python?
    primarykey
    data
    text
    <p>more-intelligent-members-of-the-coding-community-than-I! I have a python question for you all... :)</p> <p>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.</p> <pre><code>startTime = time.time() process = subprocess.Popen(['process', 'to', 'test']) process.wait() endTime = time.time() wallTime = endTime - startTime </code></pre> <p>However, I am concerned that the overhead in <code>subprocess.Popen()</code> is inflating my results on older and exotic platforms. My first inclination is to somehow time the overhead caused by <code>subprocess.Popen()</code> by running a simple innocuous command. Such as the following on linux.</p> <pre><code>startTime = time.time() process = subprocess.Popen(['touch', '/tmp/foo']) process.wait() endTime = time.time() overheadWallTime = endTime - startTime </code></pre> <p>Or the following on windows.</p> <pre><code>startTime = time.time() process = subprocess.Popen(['type', 'NUL', '&gt;', 'tmp']) process.wait() endTime = time.time() overheadWallTime = endTime - startTime </code></pre> <p>So, how should I account for <code>subprocess.Popen()</code> overhead when timing in python?</p> <p>Or, what is an innocuous way to sample the overhead from <code>subprocess.Popen()</code>?</p> <p>Or, maybe there's something I haven't considered yet?</p> <p>The caveat is that the solution must be reasonably cross-platform.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload