當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。