# HG changeset patch # User Ville Skyttä # Date 1472658352 -10800 # Wed Aug 31 18:45:52 2016 +0300 # Branch monotonic # Node ID fe2f452ac1f188963c0ef871417c0f0c965f9fb0 # Parent 1340e298aa7ef62ac657f31cd969a1db6a61ac6d Use time.monotonic instead of time.time where appropriate diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py --- a/Lib/asyncio/test_utils.py +++ b/Lib/asyncio/test_utils.py @@ -62,10 +62,10 @@ def run_until(loop, pred, timeout=30): - deadline = time.time() + timeout + deadline = time.monotonic() + timeout while not pred(): if timeout is not None: - timeout = deadline - time.time() + timeout = deadline - time.monotonic() if timeout <= 0: raise futures.TimeoutError() loop.run_until_complete(tasks.sleep(0.001, loop=loop)) diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py --- a/Lib/concurrent/futures/_base.py +++ b/Lib/concurrent/futures/_base.py @@ -189,7 +189,7 @@ before the given timeout. """ if timeout is not None: - end_time = timeout + time.time() + end_time = timeout + time.monotonic() fs = set(fs) with _AcquireFutures(fs): @@ -206,7 +206,7 @@ if timeout is None: wait_timeout = None else: - wait_timeout = end_time - time.time() + wait_timeout = end_time - time.monotonic() if wait_timeout < 0: raise TimeoutError( '%d (of %d) futures unfinished' % ( @@ -543,7 +543,7 @@ Exception: If fn(*args) raises for any values. """ if timeout is not None: - end_time = timeout + time.time() + end_time = timeout + time.monotonic() fs = [self.submit(fn, *args) for args in zip(*iterables)] @@ -555,7 +555,7 @@ if timeout is None: yield future.result() else: - yield future.result(end_time - time.time()) + yield future.result(end_time - time.monotonic()) finally: for future in fs: future.cancel() diff --git a/Lib/mailbox.py b/Lib/mailbox.py --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -522,7 +522,7 @@ # extra delta to our wait. The default is one tenth second, but is an # instance variable and so can be adjusted if dealing with a # particularly skewed or irregular system. - if time.time() - self._last_read > 2 + self._skewfactor: + if time.monotonic() - self._last_read > 2 + self._skewfactor: refresh = False for subdir in self._toc_mtimes: mtime = os.path.getmtime(self._paths[subdir]) @@ -541,7 +541,7 @@ continue uniq = entry.split(self.colon)[0] self._toc[uniq] = os.path.join(subdir, entry) - self._last_read = time.time() + self._last_read = time.monotonic() def _lookup(self, key): """Use TOC to return subpath for given key, or raise a KeyError.""" diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -57,10 +57,10 @@ def _init_timeout(timeout=CONNECTION_TIMEOUT): - return time.time() + timeout + return time.monotonic() + timeout def _check_timeout(t): - return time.time() > t + return time.monotonic() > t # # @@ -905,7 +905,7 @@ selector.register(obj, selectors.EVENT_READ) if timeout is not None: - deadline = time.time() + timeout + deadline = time.monotonic() + timeout while True: ready = selector.select(timeout) @@ -913,7 +913,7 @@ return [key.fileobj for (key, events) in ready] else: if timeout is not None: - timeout = deadline - time.time() + timeout = deadline - time.monotonic() if timeout < 0: return ready diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py +++ b/Lib/multiprocessing/managers.py @@ -19,7 +19,7 @@ import array import queue -from time import time as _time +from time import monotonic as _time from traceback import format_exc from . import connection diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py --- a/Lib/multiprocessing/queues.py +++ b/Lib/multiprocessing/queues.py @@ -95,12 +95,12 @@ self._sem.release() else: if block: - deadline = time.time() + timeout + deadline = time.monotonic() + timeout if not self._rlock.acquire(block, timeout): raise Empty try: if block: - timeout = deadline - time.time() + timeout = deadline - time.monotonic() if timeout < 0 or not self._poll(timeout): raise Empty elif not self._poll(): diff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py --- a/Lib/multiprocessing/synchronize.py +++ b/Lib/multiprocessing/synchronize.py @@ -16,7 +16,7 @@ import tempfile import _multiprocessing -from time import time as _time +from time import monotonic as _time from . import context from . import process diff --git a/Lib/pprint.py b/Lib/pprint.py --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -568,11 +568,11 @@ if object is None: object = [("string", (1, 2), [3, 4], {5: 6, 7: 8})] * 100000 p = PrettyPrinter() - t1 = time.time() + t1 = time.monotonic() _safe_repr(object, {}, None, 0) - t2 = time.time() + t2 = time.monotonic() p.pformat(object) - t3 = time.time() + t3 = time.monotonic() print("_safe_repr:", t2 - t1) print("pformat:", t3 - t2) diff --git a/Lib/random.py b/Lib/random.py --- a/Lib/random.py +++ b/Lib/random.py @@ -676,14 +676,14 @@ sqsum = 0.0 smallest = 1e10 largest = -1e10 - t0 = time.time() + t0 = time.monotonic() for i in range(n): x = func(*args) total += x sqsum = sqsum + x*x smallest = min(x, smallest) largest = max(x, largest) - t1 = time.time() + t1 = time.monotonic() print(round(t1-t0, 3), 'sec,', end=' ') avg = total/n stddev = _sqrt(sqsum/n - avg*avg) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -137,11 +137,11 @@ self.elapsed = None def __call__(self, *args, **kwds): - t = time.time() + t = time.monotonic() try: return self.func(*args, **kwds) finally: - self.elapsed = time.time() - t + self.elapsed = time.monotonic() - t # # Base class for test cases @@ -744,9 +744,9 @@ def test_timeout(self): q = multiprocessing.Queue() - start = time.time() + start = time.monotonic() self.assertRaises(pyqueue.Empty, q.get, True, 0.200) - delta = time.time() - start + delta = time.monotonic() - start # Tolerate a delta of 30 ms because of the bad clock resolution on # Windows (usually 15.6 ms) self.assertGreaterEqual(delta, 0.170) @@ -1010,9 +1010,9 @@ sem.release() with cond: expected = 0.1 - dt = time.time() + dt = time.monotonic() result = cond.wait_for(lambda : state.value==4, timeout=expected) - dt = time.time() - dt + dt = time.monotonic() - dt # borrow logic in assertTimeout() from test/lock_tests.py if not result and expected * 0.6 < dt < expected * 10.0: success.value = True @@ -1920,7 +1920,7 @@ # process would fill the result queue (after the result handler thread # terminated, hence not draining it anymore). - t_start = time.time() + t_start = time.monotonic() with self.assertRaises(ValueError): with self.Pool(2) as p: @@ -1932,7 +1932,7 @@ p.join() # check that we indeed waited for all jobs - self.assertGreater(time.time() - t_start, 0.9) + self.assertGreater(time.monotonic() - t_start, 0.9) def raising(): @@ -3355,9 +3355,9 @@ expected = 5 a, b = multiprocessing.Pipe() - start = time.time() + start = time.monotonic() res = wait([a, b], expected) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(res, []) self.assertLess(delta, expected * 2) @@ -3365,9 +3365,9 @@ b.send(None) - start = time.time() + start = time.monotonic() res = wait([a, b], 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(res, [a]) self.assertLess(delta, 0.4) @@ -3391,9 +3391,9 @@ self.assertIsInstance(p.sentinel, int) self.assertTrue(sem.acquire(timeout=20)) - start = time.time() + start = time.monotonic() res = wait([a, p.sentinel, b], expected + 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(res, [p.sentinel]) self.assertLess(delta, expected + 2) @@ -3401,18 +3401,18 @@ a.send(None) - start = time.time() + start = time.monotonic() res = wait([a, p.sentinel, b], 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(sorted_(res), sorted_([p.sentinel, b])) self.assertLess(delta, 0.4) b.send(None) - start = time.time() + start = time.monotonic() res = wait([a, p.sentinel, b], 20) - delta = time.time() - start + delta = time.monotonic() - start self.assertEqual(sorted_(res), sorted_([a, p.sentinel, b])) self.assertLess(delta, 0.4) @@ -3423,9 +3423,9 @@ def test_neg_timeout(self): from multiprocessing.connection import wait a, b = multiprocessing.Pipe() - t = time.time() + t = time.monotonic() res = wait([a], timeout=-1) - t = time.time() - t + t = time.monotonic() - t self.assertEqual(res, []) self.assertLess(t, 1) a.close() diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -147,7 +147,7 @@ # Always import it from the test package abstest = 'test.' + test with saved_test_environment(test, ns.verbose, ns.quiet, pgo=ns.pgo) as environment: - start_time = time.time() + start_time = time.monotonic() the_module = importlib.import_module(abstest) # If the test has a test_main, that will run the appropriate # tests. If not, use normal unittest test loading. @@ -164,7 +164,7 @@ test_runner() if ns.huntrleaks: refleak = dash_R(the_module, test, test_runner, ns.huntrleaks) - test_time = time.time() - start_time + test_time = time.monotonic() - start_time except support.ResourceDenied as msg: if not ns.quiet and not ns.pgo: print(test, "skipped --", msg, flush=True) diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -184,16 +184,16 @@ # TIMEOUT_MAX is ok lock.acquire(timeout=TIMEOUT_MAX) lock.release() - t1 = time.time() + t1 = time.monotonic() self.assertTrue(lock.acquire(timeout=5)) - t2 = time.time() + t2 = time.monotonic() # Just a sanity test that it didn't actually wait for the timeout. self.assertLess(t2 - t1, 5) results = [] def f(): - t1 = time.time() + t1 = time.monotonic() results.append(lock.acquire(timeout=0.5)) - t2 = time.time() + t2 = time.monotonic() results.append(t2 - t1) Bunch(f, 1).wait_for_finished() self.assertFalse(results[0]) @@ -372,9 +372,9 @@ N = 5 def f(): results1.append(evt.wait(0.0)) - t1 = time.time() + t1 = time.monotonic() r = evt.wait(0.5) - t2 = time.time() + t2 = time.monotonic() results2.append((r, t2 - t1)) Bunch(f, N).wait_for_finished() self.assertEqual(results1, [False] * N) @@ -525,9 +525,9 @@ N = 5 def f(): cond.acquire() - t1 = time.time() + t1 = time.monotonic() result = cond.wait(0.5) - t2 = time.time() + t2 = time.monotonic() cond.release() results.append((t2 - t1, result)) Bunch(f, N).wait_for_finished() @@ -564,9 +564,9 @@ success = [] def f(): with cond: - dt = time.time() + dt = time.monotonic() result = cond.wait_for(lambda : state==4, timeout=0.1) - dt = time.time() - dt + dt = time.monotonic() - dt self.assertFalse(result) self.assertTimeout(dt, 0.1) success.append(None) @@ -670,9 +670,9 @@ self.assertFalse(sem.acquire(timeout=0.005)) sem.release() self.assertTrue(sem.acquire(timeout=0.005)) - t = time.time() + t = time.monotonic() self.assertFalse(sem.acquire(timeout=0.5)) - dt = time.time() - t + dt = time.monotonic() - t self.assertTimeout(dt, 0.5) def test_default_value(self): diff --git a/Lib/test/pystone.py b/Lib/test/pystone.py --- a/Lib/test/pystone.py +++ b/Lib/test/pystone.py @@ -41,7 +41,7 @@ LOOPS = 50000 -from time import time +from time import monotonic as time __version__ = "1.2" diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1997,11 +1997,11 @@ try: if unlock: unlock() - endtime = starttime = time.time() + endtime = time.monotonic() for timeout in range(1, 16): endtime += 60 for t in started: - t.join(max(endtime - time.time(), 0.01)) + t.join(max(endtime - time.monotonic(), 0.01)) started = [t for t in started if t.isAlive()] if not started: break diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -70,8 +70,8 @@ pass else: n = 200 - start = time.time() - while n > 0 and time.time() - start < 3.0: + start = time.monotonic() + while n > 0 and time.monotonic() - start < 3.0: r, w, e = select.select([conn], [], [], 0.1) if r: n -= 1 diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -63,7 +63,7 @@ worker_count = 5 def setUp(self): - self.t1 = time.time() + self.t1 = time.monotonic() try: self.executor = self.executor_type(max_workers=self.worker_count) except NotImplementedError as e: @@ -72,7 +72,7 @@ def tearDown(self): self.executor.shutdown(wait=True) - dt = time.time() - self.t1 + dt = time.monotonic() - self.t1 if test.support.verbose: print("%.2fs" % dt, end=' ') self.assertLess(dt, 60, "synchronization issue: test lasted too long") diff --git a/Lib/test/test_dummy_thread.py b/Lib/test/test_dummy_thread.py --- a/Lib/test/test_dummy_thread.py +++ b/Lib/test/test_dummy_thread.py @@ -70,14 +70,14 @@ to_unlock.release() self.lock.acquire() - start_time = int(time.time()) + start_time = int(time.monotonic()) _thread.start_new_thread(delay_unlock,(self.lock, DELAY)) if support.verbose: print() print("*** Waiting for thread to release the lock "\ "(approx. %s sec.) ***" % DELAY) self.lock.acquire() - end_time = int(time.time()) + end_time = int(time.monotonic()) if support.verbose: print("done") self.assertGreaterEqual(end_time - start_time, DELAY, diff --git a/Lib/test/test_multiprocessing_main_handling.py b/Lib/test/test_multiprocessing_main_handling.py --- a/Lib/test/test_multiprocessing_main_handling.py +++ b/Lib/test/test_multiprocessing_main_handling.py @@ -55,10 +55,10 @@ p = Pool(5) results = [] p.map_async(f, [1, 2, 3], callback=results.extend) - deadline = time.time() + 10 # up to 10 s to report the results + deadline = time.monotonic() + 10 # up to 10 s to report the results while not results: time.sleep(0.05) - if time.time() > deadline: + if time.monotonic() > deadline: raise RuntimeError("Timed out waiting for results") results.sort() print(start_method, "->", results) @@ -83,10 +83,10 @@ p = Pool(5) results = [] p.map_async(int, [1, 4, 9], callback=results.extend) -deadline = time.time() + 10 # up to 10 s to report the results +deadline = time.monotonic() + 10 # up to 10 s to report the results while not results: time.sleep(0.05) - if time.time() > deadline: + if time.monotonic() > deadline: raise RuntimeError("Timed out waiting for results") results.sort() print(start_method, "->", results) diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -77,10 +77,10 @@ # set parameters based on .au file headers dsp.setparameters(AFMT_S16_NE, nchannels, rate) self.assertTrue(abs(expected_time - 3.51) < 1e-2, expected_time) - t1 = time.time() + t1 = time.monotonic() dsp.write(data) dsp.close() - t2 = time.time() + t2 = time.monotonic() elapsed_time = t2 - t1 percent_diff = (abs(elapsed_time - expected_time) / expected_time) * 100 diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -900,12 +900,12 @@ serverthread = pydoc._start_server(my_url_handler, port=0) self.assertIn('localhost', serverthread.docserver.address) - starttime = time.time() + starttime = time.monotonic() timeout = 1 #seconds while serverthread.serving: time.sleep(.01) - if serverthread.serving and time.time() - starttime > timeout: + if serverthread.serving and time.monotonic() - starttime > timeout: serverthread.stop() break diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -3832,12 +3832,12 @@ self.assertIsNone(self.serv.gettimeout()) self.serv.setblocking(False) self.assertEqual(self.serv.gettimeout(), 0.0) - start = time.time() + start = time.monotonic() try: self.serv.accept() except OSError: pass - end = time.time() + end = time.monotonic() self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.") def _testSetBlocking(self): @@ -3867,12 +3867,12 @@ self.port = support.bind_port(self.serv) self.serv.listen() # actual testing - start = time.time() + start = time.monotonic() try: self.serv.accept() except OSError: pass - end = time.time() + end = time.monotonic() self.assertTrue((end - start) < 1.0, "Error creating with non-blocking mode.") def _testInitNonBlocking(self): diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py --- a/Lib/test/test_threadsignals.py +++ b/Lib/test/test_threadsignals.py @@ -87,9 +87,9 @@ lock = thread.allocate_lock() lock.acquire() signal.alarm(1) - t1 = time.time() + t1 = time.monotonic() self.assertRaises(KeyboardInterrupt, lock.acquire, timeout=5) - dt = time.time() - t1 + dt = time.monotonic() - t1 # Checking that KeyboardInterrupt was raised is not sufficient. # We want to assert that lock.acquire() was interrupted because # of the signal, not that the signal handler was called immediately @@ -121,9 +121,9 @@ rlock.release() time.sleep(0.01) signal.alarm(1) - t1 = time.time() + t1 = time.monotonic() self.assertRaises(KeyboardInterrupt, rlock.acquire, timeout=5) - dt = time.time() - t1 + dt = time.monotonic() - t1 # See rationale above in test_lock_acquire_interruption self.assertLess(dt, 3.0) finally: @@ -184,9 +184,9 @@ old_handler = signal.signal(signal.SIGUSR1, my_handler) try: def timed_acquire(): - self.start = time.time() + self.start = time.monotonic() lock.acquire(timeout=0.5) - self.end = time.time() + self.end = time.monotonic() def send_signals(): for _ in range(40): time.sleep(0.02) diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -127,11 +127,11 @@ self.sock.settimeout(timeout) method = getattr(self.sock, method) for i in range(count): - t1 = time.time() + t1 = time.monotonic() try: method(*args) except socket.timeout as e: - delta = time.time() - t1 + delta = time.monotonic() - t1 break else: self.fail('socket.timeout was not raised') diff --git a/Lib/test/test_zipfile64.py b/Lib/test/test_zipfile64.py --- a/Lib/test/test_zipfile64.py +++ b/Lib/test/test_zipfile64.py @@ -44,12 +44,12 @@ # raw data to store. filecount = 6*1024**3 // len(self.data) - next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL + next_time = time.monotonic() + _PRINT_WORKING_MSG_INTERVAL for num in range(filecount): zipfp.writestr("testfn%d" % num, self.data) # Print still working message since this test can be really slow - if next_time <= time.time(): - next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL + if next_time <= time.monotonic(): + next_time = time.monotonic() + _PRINT_WORKING_MSG_INTERVAL print(( ' zipTest still writing %d of %d, be patient...' % (num, filecount)), file=sys.__stdout__) @@ -61,8 +61,8 @@ for num in range(filecount): self.assertEqual(zipfp.read("testfn%d" % num), self.data) # Print still working message since this test can be really slow - if next_time <= time.time(): - next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL + if next_time <= time.monotonic(): + next_time = time.monotonic() + _PRINT_WORKING_MSG_INTERVAL print(( ' zipTest still reading %d of %d, be patient...' % (num, filecount)), file=sys.__stdout__) diff --git a/Lib/test/time_hashlib.py b/Lib/test/time_hashlib.py --- a/Lib/test/time_hashlib.py +++ b/Lib/test/time_hashlib.py @@ -14,26 +14,26 @@ longStr = b'Z'*scale localCF = creatorFunc - start = time.time() + start = time.monotonic() for f in range(iterations): x = localCF(longStr).digest() - end = time.time() + end = time.monotonic() print(('%2.2f' % (end-start)), "seconds", iterations, "x", len(longStr), "bytes", name) def test_create(): - start = time.time() + start = time.monotonic() for f in range(20000): d = creatorFunc() - end = time.time() + end = time.monotonic() print(('%2.2f' % (end-start)), "seconds", '[20000 creations]') def test_zero(): - start = time.time() + start = time.monotonic() for f in range(20000): x = creatorFunc().digest() - end = time.time() + end = time.monotonic() print(('%2.2f' % (end-start)), "seconds", '[20000 "" digests]') diff --git a/Lib/unittest/runner.py b/Lib/unittest/runner.py --- a/Lib/unittest/runner.py +++ b/Lib/unittest/runner.py @@ -168,7 +168,7 @@ warnings.filterwarnings('module', category=DeprecationWarning, message='Please use assert\w+ instead.') - startTime = time.time() + startTime = time.monotonic() startTestRun = getattr(result, 'startTestRun', None) if startTestRun is not None: startTestRun() @@ -178,7 +178,7 @@ stopTestRun = getattr(result, 'stopTestRun', None) if stopTestRun is not None: stopTestRun() - stopTime = time.time() + stopTime = time.monotonic() timeTaken = stopTime - startTime result.printErrors() if hasattr(result, 'separator2'): diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1572,17 +1572,17 @@ def connect_ftp(self, user, passwd, host, port, dirs, timeout): key = user, host, port, '/'.join(dirs), timeout if key in self.cache: - self.timeout[key] = time.time() + self.delay + self.timeout[key] = time.monotonic() + self.delay else: self.cache[key] = ftpwrapper(user, passwd, host, port, dirs, timeout) - self.timeout[key] = time.time() + self.delay + self.timeout[key] = time.monotonic() + self.delay self.check_cache() return self.cache[key] def check_cache(self): # first check for old ones - t = time.time() + t = time.monotonic() if self.soonest <= t: for k, v in list(self.timeout.items()): if v < t: diff --git a/Modules/_decimal/tests/bench.py b/Modules/_decimal/tests/bench.py --- a/Modules/_decimal/tests/bench.py +++ b/Modules/_decimal/tests/bench.py @@ -80,7 +80,7 @@ for prec in [9, 19]: print("\nPrecision: %d decimal digits\n" % prec) for func in to_benchmark: - start = time.time() + start = time.monotonic() if C is not None: C.getcontext().prec = prec P.getcontext().prec = prec @@ -88,7 +88,7 @@ x = func() print("%s:" % func.__name__.replace("pi_", "")) print("result: %s" % str(x)) - print("time: %fs\n" % (time.time()-start)) + print("time: %fs\n" % (time.monotonic()-start)) print("\n# ======================================================================") @@ -107,23 +107,23 @@ if C is not None: # C version of decimal - start_calc = time.time() + start_calc = time.monotonic() x = factorial(C.Decimal(n), 0) - end_calc = time.time() - start_conv = time.time() + end_calc = time.monotonic() + start_conv = time.monotonic() sx = str(x) - end_conv = time.time() + end_conv = time.monotonic() print("cdecimal:") print("calculation time: %fs" % (end_calc-start_calc)) print("conversion time: %fs\n" % (end_conv-start_conv)) # Python integers - start_calc = time.time() + start_calc = time.monotonic() y = factorial(n, 0) - end_calc = time.time() - start_conv = time.time() + end_calc = time.monotonic() + start_conv = time.monotonic() sy = str(y) - end_conv = time.time() + end_conv = time.monotonic() print("int:") print("calculation time: %fs" % (end_calc-start_calc)) diff --git a/Tools/ccbench/ccbench.py b/Tools/ccbench/ccbench.py --- a/Tools/ccbench/ccbench.py +++ b/Tools/ccbench/ccbench.py @@ -86,11 +86,11 @@ arg = f.read(2000) def findall(s): - t = time.time() + t = time.monotonic() try: return pat.findall(s) finally: - print(time.time() - t) + print(time.monotonic() - t) return pat.findall, (arg, ) def task_sort(): diff --git a/Tools/pynche/ColorDB.py b/Tools/pynche/ColorDB.py --- a/Tools/pynche/ColorDB.py +++ b/Tools/pynche/ColorDB.py @@ -259,9 +259,9 @@ r, g, b = (255, 251, 250) # snow print('finding nearest to', target, '...') import time - t0 = time.time() + t0 = time.monotonic() nearest = colordb.nearest(r, g, b) - t1 = time.time() + t1 = time.monotonic() print('found nearest color', nearest, 'in', t1-t0, 'seconds') # dump the database for n in colordb.unique_names():