本文整理匯總了Python中time.clock_gettime方法的典型用法代碼示例。如果您正苦於以下問題:Python time.clock_gettime方法的具體用法?Python time.clock_gettime怎麽用?Python time.clock_gettime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類time
的用法示例。
在下文中一共展示了time.clock_gettime方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_time_ns_type
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_time_ns_type(self):
def check_ns(sec, ns):
self.assertIsInstance(ns, int)
sec_ns = int(sec * 1e9)
# tolerate a difference of 50 ms
self.assertLess((sec_ns - ns), 50 ** 6, (sec, ns))
check_ns(time.time(),
time.time_ns())
check_ns(time.monotonic(),
time.monotonic_ns())
check_ns(time.perf_counter(),
time.perf_counter_ns())
check_ns(time.process_time(),
time.process_time_ns())
if hasattr(time, 'thread_time'):
check_ns(time.thread_time(),
time.thread_time_ns())
if hasattr(time, 'clock_gettime'):
check_ns(time.clock_gettime(time.CLOCK_REALTIME),
time.clock_gettime_ns(time.CLOCK_REALTIME))
示例2: thread_clock
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def thread_clock():
return time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID)
#: Does nothing. It allows any arguments.
示例3: __enter__
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def __enter__(self):
_log.debug('>>> %s', self.section)
self.start = time.clock_gettime(time.CLOCK_MONOTONIC)
return self
示例4: __exit__
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def __exit__(self, *exc):
self.end = time.clock_gettime(time.CLOCK_MONOTONIC)
self.interval = self.end - self.start
_log.debug('<<< %s %.2fs', self.section, self.interval)
return False # re-raise
示例5: test_clock_realtime
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_clock_realtime(self):
time.clock_gettime(time.CLOCK_REALTIME)
示例6: test_clock_monotonic
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_clock_monotonic(self):
a = time.clock_gettime(time.CLOCK_MONOTONIC)
b = time.clock_gettime(time.CLOCK_MONOTONIC)
self.assertLessEqual(a, b)
示例7: test_clock_settime
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_clock_settime(self):
t = time.clock_gettime(time.CLOCK_REALTIME)
try:
time.clock_settime(time.CLOCK_REALTIME, t)
except PermissionError:
pass
if hasattr(time, 'CLOCK_MONOTONIC'):
self.assertRaises(OSError,
time.clock_settime, time.CLOCK_MONOTONIC, 0)
示例8: test_monotonic_settime
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_monotonic_settime(self):
t1 = time.monotonic()
realtime = time.clock_gettime(time.CLOCK_REALTIME)
# jump backward with an offset of 1 hour
try:
time.clock_settime(time.CLOCK_REALTIME, realtime - 3600)
except PermissionError as err:
self.skipTest(err)
t2 = time.monotonic()
time.clock_settime(time.CLOCK_REALTIME, realtime)
# monotonic must not be affected by system clock updates
self.assertGreaterEqual(t2, t1)
示例9: _set_real_base
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def _set_real_base(self, metaconvert):
self._real_base = int(
time.clock_gettime(time.CLOCK_REALTIME) *
FFmpegPipeline.SECONDS_TO_NANOSECONDS)
if ("tags" not in self.request):
self.request["tags"] = {}
self.request["tags"]["real_base"] = self._real_base
properties = self._video_filter_map[metaconvert].properties
properties["tags"] = "\'{}\'".format(
json.dumps(self.request["tags"]).replace(':', r'\:'))
示例10: monotonic
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def monotonic():
"""Monotonic clock, cannot go backward."""
ts = timespec()
if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(ts)):
errno = ctypes.get_errno()
raise OSError(errno, os.strerror(errno))
return ts.tv_sec + ts.tv_nsec / 1.0e9
# Perform a sanity-check.
示例11: clock
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def clock():
return time.clock_gettime(time.CLOCK_THREAD_CPUTIME_ID)
示例12: set_mode
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def set_mode(self, mode=MODE_SLEEP, t_sb=t_sb_1000):
# Writes ctrl_meas register with current temperature and pressure oversampling settings
# Only changes the mode
# If normal mode selected also sets the standby time in config register
# Set class variables
self.mode = mode
self.t_sb = t_sb
# If no measurements are enabled there is no point going into measurement
if self.osrs_t + self.osrs_p + self.osrs_h == 0:
print("No measurement enabled!\nSee set_oversampling()-function to enable measurement.")
return 0
try:
# If normal mode set also t_sb(standby time)
if self.mode == self.MODE_NORMAL:
# Write normal mode standby time t_sb to config register
self.__config(t_sb, self.filter, self.spi3w_en)
# Write mode to ctr_meas register
self.__ctrl_meas(self.osrs_t, self.osrs_p, self.mode)
# Otherwise just change the mode in ctrl_meas register
else:
self.__ctrl_meas(self.osrs_t, self.osrs_p, self.mode)
self.last_meas = clock_gettime(CLOCK_REALTIME)
# Everything went well return 1
return 1
except Exception as e:
# e = sys.exc_info()[0]
print("<p>Error: %s</p>" % e)
return 0
#########################################################################
# Set oversampling/enable measurement. OVRS_x0 disables the measurement #
#########################################################################
示例13: test_clock_realtime
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_clock_realtime(self):
t = time.clock_gettime(time.CLOCK_REALTIME)
self.assertIsInstance(t, float)
示例14: test_pthread_getcpuclockid
# 需要導入模塊: import time [as 別名]
# 或者: from time import clock_gettime [as 別名]
def test_pthread_getcpuclockid(self):
clk_id = time.pthread_getcpuclockid(threading.get_ident())
self.assertTrue(type(clk_id) is int)
self.assertNotEqual(clk_id, time.CLOCK_THREAD_CPUTIME_ID)
t1 = time.clock_gettime(clk_id)
t2 = time.clock_gettime(clk_id)
self.assertLessEqual(t1, t2)