Search code examples
pythonwrapperos.system

Wrapper script that would record the execution time of another script with parameters


I have a wrapper script wrapper.py that would time the full execution of benchrun.py.

Let's say I run the benchrun.py using this command:

python benchrun.py --host {host} -f {testfile} -t {number of threads} -s {mongo shell path}

What should I put in the wrapper script to run the benchrun.py script and get the execution time?


Solution

  • First, benchrun.py

    import datetime
    
    print ("sleeping now...")
    time.sleep(10)
    print ("done!") 
    

    wrapper:

    import os
    from datetime import datetime, timedelta
    
    before = datetime.now()
    os.system("python benchrun.py")
    after = datetime.now()
    
    print ("execution time: {0}".format(after - before))