本文整理汇总了Python中time.perf_counter_ns方法的典型用法代码示例。如果您正苦于以下问题:Python time.perf_counter_ns方法的具体用法?Python time.perf_counter_ns怎么用?Python time.perf_counter_ns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类time
的用法示例。
在下文中一共展示了time.perf_counter_ns方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resolve
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def resolve(
self, next_: Resolver, parent: Any, info: GraphQLResolveInfo, **kwargs
): # pylint: disable=invalid-overridden-method
if not should_trace(info):
result = next_(parent, info, **kwargs)
return result
start_timestamp = perf_counter_ns()
record = {
"path": format_path(info.path),
"parentType": str(info.parent_type),
"fieldName": info.field_name,
"returnType": str(info.return_type),
"startOffset": start_timestamp - self.start_timestamp,
}
self.resolvers.append(record)
try:
result = next_(parent, info, **kwargs)
return result
finally:
end_timestamp = perf_counter_ns()
record["duration"] = end_timestamp - start_timestamp
示例2: test_time_ns_type
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [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))
示例3: __init__
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def __init__(
self,
trace_id=None, # type: Optional[str]
span_id=None, # type: Optional[str]
parent_span_id=None, # type: Optional[str]
same_process_as_parent=True, # type: bool
sampled=None, # type: Optional[bool]
op=None, # type: Optional[str]
description=None, # type: Optional[str]
hub=None, # type: Optional[sentry_sdk.Hub]
status=None, # type: Optional[str]
transaction=None, # type: Optional[str] # deprecated
):
# type: (...) -> None
self.trace_id = trace_id or uuid.uuid4().hex
self.span_id = span_id or uuid.uuid4().hex[16:]
self.parent_span_id = parent_span_id
self.same_process_as_parent = same_process_as_parent
self.sampled = sampled
self.op = op
self.description = description
self.status = status
self.hub = hub
self._tags = {} # type: Dict[str, str]
self._data = {} # type: Dict[str, Any]
self.start_timestamp = datetime.utcnow()
try:
# TODO: For Python 3.7+, we could use a clock with ns resolution:
# self._start_timestamp_monotonic = time.perf_counter_ns()
# Python 3.3+
self._start_timestamp_monotonic = time.perf_counter()
except AttributeError:
pass
#: End timestamp of span
self.timestamp = None # type: Optional[datetime]
self._span_recorder = None # type: Optional[_SpanRecorder]
示例4: perf_counter_ns
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def perf_counter_ns() -> int:
return int(perf_counter() * NS_IN_SECOND)
示例5: request_started
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def request_started(self, context: ContextValue):
self.start_date = datetime.datetime.utcnow()
self.start_timestamp = perf_counter_ns()
示例6: _get_totals
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def _get_totals(self):
return {
"start": self.start_date,
"end": datetime.datetime.utcnow(),
"duration": perf_counter_ns() - self.start_timestamp,
"resolvers": self.resolvers,
}
示例7: perf_counter_ns
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def perf_counter_ns():
"""Compatibility version for pre Python 3.7."""
return int(time.perf_counter() * 1e9)
示例8: perf_counter_ns
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def perf_counter_ns():
"""
Shim for standard library time.perf_counter for Python < 3.7.
"""
return int(time.perf_counter() * 1000000000.)
示例9: time_ns
# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def time_ns():
return perf_counter_ns()