[issue2205] os.times() returns incorrect value

makoto kuwata report at bugs.python.org
Fri Feb 29 03:08:39 CET 2008


makoto kuwata added the comment:

I'm sorry to put empty submit.

os.time() returns incorrect value.

test.py:

    def f(n):
      if n <= 0:
          return 1
      else:
          return f(n-1) + f(n-2)
    
    import os
    t1 = os.times()
    f(34)
    t2 = os.times()
    
    utime = t2[0] - t1[0]
    stime = t2[1] - t1[1]
    total = utime + stime
    
    print "utime %.4f, stime %.4f, total %.4f" % (utime, stime, total)

result:

    $ time python bench.py
    utime 38.6333, stime 0.1000, total 38.7333
    
    real    0m23.787s
    user    0m23.211s
    sys     0m0.138s

This shows that real time is only 23.8 seconds, but os.times()
reports that user time is over 38 seconds.

This is due to bug of Modules/posixmodule.c.

Environment: python 2.5.2, MacOS X 10.4 Tiger, GCC 4.0

----------
keywords: +patch
title: os.times() returns uncorrect value -> os.times() returns incorrect value
Added file: http://bugs.python.org/file9568/posixmodule.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2205>
__________________________________


More information about the Python-bugs-list mailing list