result of os.times() is different with 'time' command Options

hiral hiralsmaillist at gmail.com
Fri Mar 12 08:49:04 EST 2010


Hi,

Python version: 2.6

Script:
def pt(start_time, end_time):
    def ptime(time, time_str):
        min, sec = divmod(time, 60)
        hr, min = divmod(min, 60)
        stmt = time_str + '\t'
        if hr:
            stmt += str(hr) + 'h'
        stmt += str(min) + 'm' + str(sec) + 's'
        print stmt

    if start_time and end_time:
        real_time  = end_time[4] - start_time[4]
        ptime(real_time, "real")
        user_time  = end_time[0] - start_time[0]
        ptime(user_time, "user")
        sys_time   = end_time[1] - start_time[1]
        ptime(sys_time, "sys")

import os, subprocess
cmd = ['ls']
print cmd
t1 = os.times()
subprocess.call(cmd)
t2 = os.times()
pt(t1, t2)
print ".end"


Output:
real    0.0m0.0100000002421s
user    0.0m0.0s
sys     0.0m0.0s


Command:
$ time ls

Output:
real    0m0.007s
user    0m0.000s
sys     0m0.000s


Is this the intended behaviour?

As per the link <http://groups.google.com/group/comp.lang.python/
browse_thread/thread/8032897a30781df/c656a79d4c3268a6> it was fixed in
python 2.5.

Can anybody help.

Thank you.







More information about the Python-list mailing list