[IronPython] time module

Michael Foord michael.foord at resolversystems.com
Fri Apr 28 11:10:04 CEST 2006

Hello all,

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 ?

Michael Foord

.. [#] See the following page for basically full code to do this, 

More information about the Ironpython-users mailing list