result of os.times() is different with 'time' command
aspineux
aspineux at gmail.com
Fri Feb 2 15:06:36 EST 2007
I dont see anything wrong !
Did you try to measure time with your watch ?
Did you try a simple python test.py without the time command ?
Maybe python is 'disturbed' by the intel core
Here my result on a linux dual AMD, python 2.4.3
# time python test.py
n=35, v=14930352
utime=22.54, stime=0.02
real 0m22.755s
user 0m22.564s
sys 0m0.022s
can you try this ?
# strace python test.py 2>&1 | grep time
times({tms_utime=1, tms_stime=1, tms_cutime=0, tms_cstime=0}) =
430217777
times({tms_utime=2238, tms_stime=2, tms_cutime=0, tms_cstime=0}) =
430220049
write(1, "n=35, v=14930352\nutime=22.37, st"..., 41n=35, v=14930352
utime=22.37, stime=0.01
now you can compare what your system replied and what python
returned !
On 2 fév, 19:30, kwa... at gmail.com wrote:
> Hi,
>
> I have a question about os.times().
> os.times() returns a tuple containing user time and system time,
> but it is not matched to the result of 'time' command.
> For example, os.times() reports that user time is 39.85 sec,
> but 'time' command reports that user time is 28.55sec.
> (machine: Python2.5, MacOS X 10.4 Tiger, MacBook 1.83GHz intel core
> duo)
>
> file: ostimetest.py
> --------------------
> import os
>
> ## benchmark function
> def f(x):
> if x <= 1:
> return 1
> else:
> return f(x-1) + f(x-2)
>
> ## do benchmark
> n = 35
> t1 = os.times() # start time
> v = f(n) # end time
> print "n=%d, v=%d" % (n, v)
> t2 = os.times()
>
> ## print result
> utime = t2[0] - t1[0] # user time
> stime = t2[1] - t1[1] # system time
> print "utime=%s, stime=%s" % (utime, stime)
> --------------------
>
> Result:
> ====================
> $ python -V
> Python 2.5
> $ time python ostimetest.py
> n=35, v=14930352
> utime=39.85, stime=0.216666666667
> real 0m28.554suser 0m23.938ssys 0m0.177s
> ====================
>
> This shows that os.times() reports that user time is 39.85sec,
> but time command shows that user time is 23.938sec.
> Why os.times() reports wrong result? Do I have any mistake?
>
> --
> kwatch
More information about the Python-list
mailing list