本文整理匯總了Python中time.get_clock_info方法的典型用法代碼示例。如果您正苦於以下問題:Python time.get_clock_info方法的具體用法?Python time.get_clock_info怎麽用?Python time.get_clock_info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類time
的用法示例。
在下文中一共展示了time.get_clock_info方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: collect_time
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def collect_time(info_add):
import time
info_add('time.time', time.time())
attributes = (
'altzone',
'daylight',
'timezone',
'tzname',
)
copy_attributes(info_add, time, 'time.%s', attributes)
if hasattr(time, 'get_clock_info'):
for clock in ('clock', 'monotonic', 'perf_counter',
'process_time', 'thread_time', 'time'):
try:
# prevent DeprecatingWarning on get_clock_info('clock')
with warnings.catch_warnings(record=True):
clock_info = time.get_clock_info(clock)
except ValueError:
# missing clock like time.thread_time()
pass
else:
info_add('time.get_clock_info(%s)' % clock, clock_info)
示例2: __init__
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def __init__(self):
self._timer_cancelled_count = 0
self._closed = False
self._stopping = False
self._ready = collections.deque()
self._scheduled = []
self._default_executor = None
self._internal_fds = 0
# Identifier of the thread running the event loop, or None if the
# event loop is not running
self._thread_id = None
self._clock_resolution = time.get_clock_info('monotonic').resolution
self._exception_handler = None
self.set_debug((not sys.flags.ignore_environment
and bool(os.environ.get('PYTHONASYNCIODEBUG'))))
# In debug mode, if the execution of a callback or a step of a task
# exceed this duration in seconds, the slow callback/task is logged.
self.slow_callback_duration = 0.1
self._current_handle = None
self._task_factory = None
self._coroutine_wrapper_set = False
示例3: test_monotonic
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_monotonic(self):
# monotonic() should not go backward
times = [time.monotonic() for n in range(100)]
t1 = times[0]
for t2 in times[1:]:
self.assertGreaterEqual(t2, t1, "times=%s" % times)
t1 = t2
# monotonic() includes time elapsed during a sleep
t1 = time.monotonic()
time.sleep(0.5)
t2 = time.monotonic()
dt = t2 - t1
self.assertGreater(t2, t1)
# Issue #20101: On some Windows machines, dt may be slightly low
self.assertTrue(0.45 <= dt <= 1.0, dt)
# monotonic() is a monotonic but non adjustable clock
info = time.get_clock_info('monotonic')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)
示例4: __init__
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def __init__(self):
self._timer_cancelled_count = 0
self._closed = False
self._ready = collections.deque()
self._scheduled = []
self._default_executor = None
self._internal_fds = 0
# Identifier of the thread running the event loop, or None if the
# event loop is not running
self._thread_id = None
self._clock_resolution = time.get_clock_info('monotonic').resolution
self._exception_handler = None
self._debug = (not sys.flags.ignore_environment
and bool(os.environ.get('PYTHONASYNCIODEBUG')))
# In debug mode, if the execution of a callback or a step of a task
# exceed this duration in seconds, the slow callback/task is logged.
self.slow_callback_duration = 0.1
self._current_handle = None
示例5: collect_time
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def collect_time(info_add):
import time
info_add('time.time', time.time())
attributes = (
'altzone',
'daylight',
'timezone',
'tzname',
)
copy_attributes(info_add, time, 'time.%s', attributes)
if hasattr(time, 'get_clock_info'):
for clock in ('time', 'perf_counter'):
tinfo = time.get_clock_info(clock)
info_add('time.get_clock_info(%s)' % clock, tinfo)
示例6: test_thread_time
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_thread_time(self):
if not hasattr(time, 'thread_time'):
if sys.platform.startswith(('linux', 'win')):
self.fail("time.thread_time() should be available on %r"
% (sys.platform,))
else:
self.skipTest("need time.thread_time")
# thread_time() should not include time spend during a sleep
start = time.thread_time()
time.sleep(0.100)
stop = time.thread_time()
# use 20 ms because thread_time() has usually a resolution of 15 ms
# on Windows
self.assertLess(stop - start, 0.020)
info = time.get_clock_info('thread_time')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)
示例7: test_get_clock_info
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_get_clock_info(self):
clocks = ['clock', 'monotonic', 'perf_counter', 'process_time', 'time']
for name in clocks:
if name == 'clock':
with self.assertWarns(DeprecationWarning):
info = time.get_clock_info('clock')
else:
info = time.get_clock_info(name)
#self.assertIsInstance(info, dict)
self.assertIsInstance(info.implementation, str)
self.assertNotEqual(info.implementation, '')
self.assertIsInstance(info.monotonic, bool)
self.assertIsInstance(info.resolution, float)
# 0.0 < resolution <= 1.0
self.assertGreater(info.resolution, 0.0)
self.assertLessEqual(info.resolution, 1.0)
self.assertIsInstance(info.adjustable, bool)
self.assertRaises(ValueError, time.get_clock_info, 'xxx')
示例8: test_time
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_time(self):
time.time()
info = time.get_clock_info('time')
self.assertFalse(info.monotonic)
self.assertTrue(info.adjustable)
示例9: test_clock
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_clock(self):
time.clock()
info = time.get_clock_info('clock')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)
示例10: test_process_time
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_process_time(self):
# process_time() should not include time spend during a sleep
start = time.process_time()
time.sleep(0.100)
stop = time.process_time()
# use 20 ms because process_time() has usually a resolution of 15 ms
# on Windows
self.assertLess(stop - start, 0.020)
info = time.get_clock_info('process_time')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)
示例11: __init__
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def __init__(self):
self._timer_cancelled_count = 0
self._closed = False
self._stopping = False
self._ready = collections.deque()
self._scheduled = []
self._default_executor = None
self._internal_fds = 0
# Identifier of the thread running the event loop, or None if the
# event loop is not running
self._thread_id = None
self._clock_resolution = time.get_clock_info('monotonic').resolution
self._exception_handler = None
self.set_debug(coroutines._is_debug_mode())
# In debug mode, if the execution of a callback or a step of a task
# exceed this duration in seconds, the slow callback/task is logged.
self.slow_callback_duration = 0.1
self._current_handle = None
self._task_factory = None
self._coroutine_origin_tracking_enabled = False
self._coroutine_origin_tracking_saved_depth = None
# A weak set of all asynchronous generators that are
# being iterated by the loop.
self._asyncgens = weakref.WeakSet()
# Set to True when `loop.shutdown_asyncgens` is called.
self._asyncgens_shutdown_called = False
示例12: __init__
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def __init__(self):
self._timer_cancelled_count = 0
self._closed = False
self._stopping = False
self._ready = collections.deque()
self._scheduled = []
self._default_executor = None
self._internal_fds = 0
# Identifier of the thread running the event loop, or None if the
# event loop is not running
self._thread_id = None
self._clock_resolution = time.get_clock_info('monotonic').resolution
self._exception_handler = None
self.set_debug((not sys.flags.ignore_environment
and bool(os.environ.get('PYTHONASYNCIODEBUG'))))
# In debug mode, if the execution of a callback or a step of a task
# exceed this duration in seconds, the slow callback/task is logged.
self.slow_callback_duration = 0.1
self._current_handle = None
self._task_factory = None
self._coroutine_wrapper_set = False
if hasattr(sys, 'get_asyncgen_hooks'):
# Python >= 3.6
# A weak set of all asynchronous generators that are
# being iterated by the loop.
self._asyncgens = weakref.WeakSet()
else:
self._asyncgens = None
# Set to True when `loop.shutdown_asyncgens` is called.
self._asyncgens_shutdown_called = False
示例13: test_clock
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def test_clock(self):
with self.assertWarns(DeprecationWarning):
time.clock()
with self.assertWarns(DeprecationWarning):
info = time.get_clock_info('clock')
self.assertTrue(info.monotonic)
self.assertFalse(info.adjustable)
示例14: timeit
# 需要導入模塊: import time [as 別名]
# 或者: from time import get_clock_info [as 別名]
def timeit(measure_func, precision):
"""
Measure the process time for measure_func with the desired precision, and
return a tuple(mean_us, stdev_us, num_runs, num_out).
"""
num_runs = 100 # Number of measurements to eliminate outliers
min_rep = 5 # Minimum number of repetitions
res_s = get_clock_info('process_time').resolution
# Determine number of repetitions needed based on desired precision and
# given timer resolution
t1_s = process_time()
measure_func()
t2_s = process_time()
t_s = t2_s - t1_s
rep = max(int(float(res_s) / t_s / precision), min_rep) \
if t_s != 0 else min_rep
# Perform the measurement a number of times and store the results
results = []
for _ in six.moves.range(num_runs):
t1_s = process_time()
for _j in six.moves.range(rep): # pylint: disable=unused-variable
measure_func()
t2_s = process_time()
t_us = 1.0E6 * (t2_s - t1_s) / rep
results.append(t_us)
# Eliminate upper outliers in the results. Even though we measure process
# time, it includes any activities done by the Python process outside of
# our actual measured code.
mean = statistics.mean(results)
stdev = statistics.stdev(results)
cleaned_results = []
outliers = []
for x in results:
if x < mean + 1 * stdev:
cleaned_results.append(x)
else:
outliers.append(x)
num_out = len(outliers)
# Calculate mean and standard deviation from cleaned results
mean_us = statistics.mean(cleaned_results)
stdev_us = statistics.stdev(cleaned_results)
return mean_us, stdev_us, num_runs, num_out