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

Tim Roberts timr at
Mon Mar 15 03:14:56 CET 2010

hiral <hiralsmaillist at> wrote:
>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?

What is it that you are wondering about?  The formatting difference is due
to your code.  The difference between 10 milliseconds and 7 milliseconds
could be due to any number of things.  First, you have the overhead of
Python involved in your measurements.  Second, you have the variability of
memory caching and disk caching.  Your Python code causes /bin/ls to be
loaded into memory, and it's probably still in a file cache when you run
the second command.

You can't really do an analysis like this with a task that only takes a few
milliseconds.  There are too many variables.
Tim Roberts, timr at
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list