get how much time python subprocess spends
Question: I'd like to time how long does the subprocess take. I tried to use

    
    
    start = time.time()
    subprocess.call('....')
    elapsed = (time.time() - start)
    

However it's not very accurate (not sure related to multi-process or sth else)
Is there a better way I can get how much time the subprocess really spends?

Thank you!


Answer: It depends on which time you want; elapsed time, user mode, system mode?

With
[`resource.getrusage`](http://docs.python.org/2/library/resource.html#resource.getrusage)
you can query the user mode and system mode time of the current process's
children. This only works on UNIX platforms (like e.g. Linux, BSD and OS X):

    
    
    import resource
    info = resource.getrusage(resource.RUSAGE_CHILDREN)
    

On Windows you'll probably have to use
[`ctypes`](http://docs.python.org/2/library/ctypes.html) to get equivalent
information from the WIN32 API.

