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

hiral hiralsmaillist at
Fri Mar 12 14:49:04 CET 2010


Python version: 2.6

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()
t2 = os.times()
pt(t1, t2)
print ".end"

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

$ time ls

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

Is this the intended behaviour?

As per the link <
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