mytools.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目: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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号