Python time 模块,h() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用time.h()

项目:chat    作者:Decalogue    | 项目源码 | 文件源码
def time_me(info="used", format_string="ms"):
    """Performance analysis - time

    Decorator of time performance analysis.
    ????——????
    ????(wall clock time, elapsed time)???????????????????????
    ???????????CPU???????????????C++/Windows?????<time.h>???
    ??????????????????
    1.time.clock()??????????????CPU????????????????time.time()????
    time.clock()?????????????UNIX?????????"????"?????????????????
    ??WINDOWS????????????????????????????????????
    ???????????????????WIN32?QueryPerformanceCounter()???????????????
    2.time.perf_counter()?????????????????????????????
    ???????????????????????
    3.time.process_time()???????

    Args:
        info: Customize print info. ????????
        format_string: Specifies the timing unit. ?????????'s': ??'ms': ???
            Defaults to 's'.
    """
    def _time_me(func):
        @wraps(func)
        def _wrapper(*args, **kwargs):
            start = time.clock()
            # start = time.perf_counter()
            # start = time.process_time()
            result = func(*args, **kwargs)
            end = time.clock()
            if format_string == "s":
                print("%s %s %s"%(func.__name__, info, end - start), "s")
            elif format_string == "ms":
                print("%s %s %s" % (func.__name__, info, 1000*(end - start)), "ms")
            return result
        return _wrapper
    return _time_me
项目:Theano-Deep-learning    作者:GeekLiB    | 项目源码 | 文件源码
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>']