当前位置: 首页>>代码示例>>Python>>正文


Python time.perf_counter_ns方法代码示例

本文整理汇总了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 
开发者ID:mirumee,项目名称:ariadne,代码行数:24,代码来源:apollotracing.py

示例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)) 
开发者ID:bkerler,项目名称:android_universal,代码行数:26,代码来源:test_time.py

示例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] 
开发者ID:getsentry,项目名称:sentry-python,代码行数:41,代码来源:tracing.py

示例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) 
开发者ID:mirumee,项目名称:ariadne,代码行数:4,代码来源:apollotracing.py

示例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() 
开发者ID:mirumee,项目名称:ariadne,代码行数:5,代码来源:apollotracing.py

示例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,
        } 
开发者ID:mirumee,项目名称:ariadne,代码行数:9,代码来源:apollotracing.py

示例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) 
开发者ID:napari,项目名称:napari,代码行数:5,代码来源:_compat.py

示例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.) 
开发者ID:crossbario,项目名称:txaio,代码行数:7,代码来源:_util.py

示例9: time_ns

# 需要导入模块: import time [as 别名]
# 或者: from time import perf_counter_ns [as 别名]
def time_ns():
        return perf_counter_ns() 
开发者ID:eveem-org,项目名称:panoramix,代码行数:4,代码来源:profiler.py


注:本文中的time.perf_counter_ns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。