mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #10278: Drop time.monotonic() function, rename time.wallclock() to time.steady()
* On Mac OS X, time.steady() now uses mach_absolute_time(), a monotonic clock * Optimistic change: bet that CLOCK_MONOTONIC and CLOCK_REALTIME are available when clock_gettime() is available * Rewrite time.steady() documentation
This commit is contained in:
parent
5e5451940c
commit
ec919cc74d
4 changed files with 27 additions and 109 deletions
|
@ -331,29 +331,10 @@ class TimeTestCase(unittest.TestCase):
|
|||
pass
|
||||
self.assertEqual(time.strftime('%Z', tt), tzname)
|
||||
|
||||
@unittest.skipUnless(hasattr(time, 'monotonic'),
|
||||
'need time.monotonic()')
|
||||
def test_monotonic(self):
|
||||
t1 = time.monotonic()
|
||||
t2 = time.monotonic()
|
||||
self.assertGreaterEqual(t2, t1)
|
||||
|
||||
t1 = time.monotonic()
|
||||
def test_steady(self):
|
||||
t1 = time.steady()
|
||||
time.sleep(0.1)
|
||||
t2 = time.monotonic()
|
||||
dt = t2 - t1
|
||||
self.assertGreater(t2, t1)
|
||||
self.assertAlmostEqual(dt, 0.1, delta=0.2)
|
||||
|
||||
def test_wallclock(self):
|
||||
t1 = time.wallclock()
|
||||
t2 = time.wallclock()
|
||||
# may fail if the system clock was changed
|
||||
self.assertGreaterEqual(t2, t1)
|
||||
|
||||
t1 = time.wallclock()
|
||||
time.sleep(0.1)
|
||||
t2 = time.wallclock()
|
||||
t2 = time.steady()
|
||||
dt = t2 - t1
|
||||
# may fail if the system clock was changed
|
||||
self.assertGreater(t2, t1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue