[IronPython] time module
dinov at exchange.microsoft.com
Fri Apr 28 17:27:19 CEST 2006
Yes, it should be possible - .NET provides us the Stopwatch class for this reason in 2.0. I've opened a beta 7 bug for this.
Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Friday, April 28, 2006 2:10 AM
To: Discussion of IronPython
Subject: [IronPython] time module
I was surprised to note that the IronPython module provides dramatically
less resolution than the cPython equivalent.
Both ``time.time()`` and ``time.clock()`` provide a resolution of only
tenths of a second.
This module is obviously heavily dependent on the underlying platform.
In fact the standard Python docs warn, of ``time.time`` :
Return the time as a floating point number expressed in seconds
since the epoch, in UTC. Note that even though the time is always
returned as a floating point number, not all systems provide time
with a better precision than 1 second. While this function normally
returns non-decreasing values, it can return a lower value than a
previous call if the system clock has been set back between the two
*However*, of ``time.clock()``, the docs say :
On Unix, return the current processor time as a floating point
number expressed in seconds. The precision, and in fact the very
definition of the meaning of ``processor time'', depends on that of the
C function of the same name, but in any case, this is the function to
use for benchmarking Python or timing algorithms.
On Windows, this function returns wall-clock seconds elapsed since
the first call to this function, as a floating point number, based on
the Win32 function QueryPerformanceCounter(). The resolution is
typically better than one microsecond.
This means that ``time.clock()`` no longer functions usefully, or as
described in the docs.
For our profiling we started to use ``System.DateTime.Now``, but
discovered this had a resolution of about 15ms. This was too small an
increment for measuring some of our recursive functions.
We ended up using ``QueryPerformanceCounter`` from C# [#]_. Would it be
possible to re-implement ``time.clock`` so that it is useful ?
.. [#] See the following page for basically full code to do this,
users mailing list
users at lists.ironpython.com
More information about the Ironpython-users