Index: Doc/library/time.rst =================================================================== --- Doc/library/time.rst (revision 85963) +++ Doc/library/time.rst (working copy) @@ -152,7 +152,22 @@ :c:func:`QueryPerformanceCounter`. The resolution is typically better than one microsecond. +.. function:: wallclock() + .. index:: + single: Wallclock + single: benchmarking + + Return the current time in fractions of a second to the system's best ability. + Use this when the most accurate representation of wall-clock is required, i.e. + when "processor time" is inappropriate. The reference point of the returned + value is undefined so only the difference of consecutive calls is valid. + + The current implementation uses :c:func:`QueryPerformanceCounter` on Windows + and c:func:`time` on other platforms. See caveats regarding c:func:`time` below. + + .. versionadded: 3.2 + .. function:: ctime([secs]) Convert a time expressed in seconds since the epoch to a string representing Index: Lib/test/test_time.py =================================================================== --- Lib/test/test_time.py (revision 85963) +++ Lib/test/test_time.py (working copy) @@ -224,6 +224,13 @@ t1 = time.mktime(lt1) self.assertTrue(0 <= (t1-t0) < 0.2) + def test_wallclock(self): + t0 = time.wallclock() + time.sleep(0.1) + t1 = time.wallclock() + t = t1 - t0 + self.assertAlmostEqual(t, 0.1, places=2) + class TestLocale(unittest.TestCase): def setUp(self): self.oldloc = locale.setlocale(locale.LC_ALL) Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 85963) +++ Modules/timemodule.c (working copy) @@ -133,6 +133,9 @@ } #define HAVE_CLOCK /* So it gets included in the methods */ +#define WALLCLOCK time_clock /* use this as wallclock() */ +#else +#define WALLCLOCK time_time /* use time as wallclock() */ #endif /* MS_WINDOWS && !defined(__BORLANDC__) */ #ifdef HAVE_CLOCK @@ -144,6 +147,15 @@ records."); #endif +#ifdef WALLCLOCK +PyDoc_STRVAR(wallclock_doc, +"wallclock() -> floating point number\n\ +\n\ +Return the real time to the best of the system's ability. The absolute\n\ +value is not specified and only relative values between subsequent calls\n\ +are defined to have meaning."); +#endif + static PyObject * time_sleep(PyObject *self, PyObject *args) { @@ -825,6 +837,9 @@ #ifdef HAVE_CLOCK {"clock", time_clock, METH_NOARGS, clock_doc}, #endif +#ifdef WALLCLOCK + {"wallclock", WALLCLOCK, METH_NOARGS, wallclock_doc}, +#endif {"sleep", time_sleep, METH_VARARGS, sleep_doc}, {"gmtime", time_gmtime, METH_VARARGS, gmtime_doc}, {"localtime", time_localtime, METH_VARARGS, localtime_doc},