• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python time.get_clock_info函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中time.get_clock_info函数的典型用法代码示例。如果您正苦于以下问题:Python get_clock_info函数的具体用法?Python get_clock_info怎么用?Python get_clock_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_clock_info函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self):
        # Unix + CLOCK_MONOTONIC_RAW
        if hasattr(time, 'clock_gettime') and hasattr(time, 'CLOCK_MONOTONIC_RAW'):
            self.info = time.get_clock_info('monotonic')
            self.info.implementation = 'clock_gettime(CLOCK_MONOTONIC_RAW)'

            def _clock():
                return time.clock_gettime(time.CLOCK_MONOTONIC_RAW)

            self.clock = _clock
            self.clock()
            return

        # All other platforms
        for mode in ('perf_counter', 'monotonic', 'clock'):
            try:
                self.info = time.get_clock_info(mode)
            except ValueError:
                continue
            if not self.info.monotonic:
                continue
            if self.info.resolution > 1e-06:
                continue
            self.clock = getattr(time, mode)
            self.clock()
            return

        raise NotImplementedError()
开发者ID:rfinnie,项目名称:2ping,代码行数:28,代码来源:monotonic_clock.py


示例2: test_thread_time

    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)

        # thread_time() should include CPU time spent in current thread...
        start = time.thread_time()
        busy_wait(0.100)
        stop = time.thread_time()
        self.assertGreaterEqual(stop - start, 0.020)  # machine busy?

        # ...but not in other threads
        t = threading.Thread(target=busy_wait, args=(0.100,))
        start = time.thread_time()
        t.start()
        t.join()
        stop = time.thread_time()
        self.assertLess(stop - start, 0.020)

        info = time.get_clock_info('thread_time')
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjustable)
开发者ID:1st1,项目名称:cpython,代码行数:33,代码来源:test_time.py


示例3: test_process_time

    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)

        # process_time() should include CPU time spent in any thread
        start = time.process_time()
        busy_wait(0.100)
        stop = time.process_time()
        self.assertGreaterEqual(stop - start, 0.020)  # machine busy?

        t = threading.Thread(target=busy_wait, args=(0.100,))
        start = time.process_time()
        t.start()
        t.join()
        stop = time.process_time()
        self.assertGreaterEqual(stop - start, 0.020)  # machine busy?

        info = time.get_clock_info('process_time')
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjustable)
开发者ID:1st1,项目名称:cpython,代码行数:25,代码来源:test_time.py


示例4: analyse_time

def analyse_time(size_to_test, no_of_trials):
    """This function takes list of array and number of trials as argument. It prints time taken to perfrom giftwrap algorithm for given lists"""
    
    if sys.version_info < (3, 3):
        get_time = time.clock
    else:
        get_time = time.perf_counter
        REZ = time.get_clock_info('perf_counter').resolution   

    total_time = 0  
    for trial in range(no_of_trials):
        list_to_test = generate_random_array(size_to_test)
        start = get_time()
        sol = grahamscan_e(list_to_test)
        end = get_time()
        total_time += (end - start)
        
    time_taken_per_locate = (1.0*total_time) / no_of_trials
    print('finish timing for array with {} random points'.format(size_to_test))
    
    #Uncomment if want graph
    #draw_graph(list_to_test, sol)
    
    print(size_to_test)
    print(time_taken_per_locate)
    return time_taken_per_locate
开发者ID:kki32,项目名称:Convex-hull-algorithm,代码行数:26,代码来源:grahamscan_e.py


示例5: test_process_time

    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)

        # bpo-33723: A busy loop of 100 ms should increase process_time()
        # by at least 15 ms
        min_time = 0.015
        busy_time = 0.100

        # process_time() should include CPU time spent in any thread
        start = time.process_time()
        busy_wait(busy_time)
        stop = time.process_time()
        self.assertGreaterEqual(stop - start, min_time)

        t = threading.Thread(target=busy_wait, args=(busy_time,))
        start = time.process_time()
        t.start()
        t.join()
        stop = time.process_time()
        self.assertGreaterEqual(stop - start, min_time)

        info = time.get_clock_info('process_time')
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjustable)
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:30,代码来源:test_time.py


示例6: __init__

 def __init__(self):
     self._ready = collections.deque()
     self._scheduled = []
     self._default_executor = None
     self._internal_fds = 0
     self._running = False
     self._granularity = time.get_clock_info('monotonic').resolution
开发者ID:tclh123,项目名称:cpython,代码行数:7,代码来源:base_events.py


示例7: collect_time

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)
开发者ID:Eyepea,项目名称:cpython,代码行数:25,代码来源:pythoninfo.py


示例8: test_clock

    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)
开发者ID:1st1,项目名称:cpython,代码行数:8,代码来源:test_time.py


示例9: test_process_time

    def test_process_time(self):
        start = time.process_time()
        time.sleep(0.1)
        stop = time.process_time()
        self.assertLess(stop - start, 0.01)

        info = time.get_clock_info('process_time')
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjusted)
开发者ID:Naddiseo,项目名称:cpython,代码行数:9,代码来源:test_time.py


示例10: __init__

 def __init__(self):
     self._closed = False
     self._ready = collections.deque()
     self._scheduled = []
     self._default_executor = None
     self._internal_fds = 0
     self._running = False
     self._clock_resolution = time.get_clock_info('monotonic').resolution
     self._exception_handler = None
     self._debug = False
开发者ID:GoMADAO,项目名称:Lessa-PLT,代码行数:10,代码来源:base_events.py


示例11: test_monotonic

    def test_monotonic(self):
        t1 = time.monotonic()
        time.sleep(0.1)
        t2 = time.monotonic()
        dt = t2 - t1
        self.assertGreater(t2, t1)
        self.assertAlmostEqual(dt, 0.1, delta=0.2)

        info = time.get_clock_info("monotonic")
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjustable)
开发者ID:juleskt,项目名称:ek128_work,代码行数:11,代码来源:test_time.py


示例12: test_get_clock_info

    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')
开发者ID:1st1,项目名称:cpython,代码行数:21,代码来源:test_time.py


示例13: test_monotonic

    def test_monotonic(self):
        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)

        info = time.get_clock_info('monotonic')
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjustable)
开发者ID:pykomke,项目名称:Kurz_Python_KE,代码行数:12,代码来源:test_time.py


示例14: test_process_time

    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)
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:12,代码来源:test_time.py


示例15: __init__

 def __init__(self):
     self._closed = False
     self._ready = collections.deque()
     self._scheduled = []
     self._default_executor = None
     self._internal_fds = 0
     self._running = False
     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
开发者ID:alex,项目名称:cpython,代码行数:14,代码来源:base_events.py


示例16: test_monotonic

    def test_monotonic(self):
        t1 = time.monotonic()
        time.sleep(0.1)
        t2 = time.monotonic()
        dt = t2 - t1
        self.assertGreater(t2, t1)
        self.assertAlmostEqual(dt, 0.1, delta=0.2)

        info = time.get_clock_info('monotonic')
        self.assertTrue(info.monotonic)
        if sys.platform == 'linux':
            self.assertTrue(info.adjusted)
        else:
            self.assertFalse(info.adjusted)
开发者ID:Naddiseo,项目名称:cpython,代码行数:14,代码来源:test_time.py


示例17: collect_time

def collect_time(info_add):
    import 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.%s' % clock, tinfo)
开发者ID:1st1,项目名称:cpython,代码行数:15,代码来源:pythoninfo.py


示例18: test_get_clock_info

    def test_get_clock_info(self):
        clocks = ['clock', 'perf_counter', 'process_time', 'time']
        if hasattr(time, 'monotonic'):
            clocks.append('monotonic')

        for name in clocks:
            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')
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:18,代码来源:test_time.py


示例19: test_get_clock_info

    def test_get_clock_info(self):
        clocks = ["clock", "perf_counter", "process_time", "time"]
        if hasattr(time, "monotonic"):
            clocks.append("monotonic")

        for name in clocks:
            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")
开发者ID:juleskt,项目名称:ek128_work,代码行数:18,代码来源:test_time.py


示例20: __init__

 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.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
开发者ID:davidsansome,项目名称:cpython,代码行数:19,代码来源:base_events.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time.gmtime函数代码示例发布时间:2022-05-27
下一篇:
Python time.delay函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap