I am trying to write a python script that benchmarks several pieces of code. The issue is when the script is run the output of the command id different from what I would get it I run it directly at bash prompt.
Here is the code for the python script
import subprocess
import re
import os
app = os.getcwd() + "/" + "myapp"
testPopen = subprocess.Popen(args=['/usr/bin/time',app],
stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=False)
testPopen.wait()
Here is the ouput of above code
real 1.0
user 0.8
sys 0.0
When you run
time myappfrom the bash prompt, you are using bash’stimecommand. (Typehelp timeto see that bash understands it as a bash command.)When you run the python script you are using
/usr/bin/time, which is a different program. (Typeman timeorwhich timeto see that time is also a program. How confusing!)To get the python script to use the bash time command: