zoukankan      html  css  js  c++  java
  • Python学习-一个简单的计时器

    在实际开发中,往往想要计算一段代码执行多长时间,以下我将该功能写入到一个函数里面,仅仅要在每一个函数前面调用该函数就可以,见以下代码:

    #--------------------------------
    #一个记时器,仅仅要在函数前面写上@fun_timer就可以
    import time
    from functools import wraps  
    def fun_timer(function):
        @wraps(function)
        def function_timer(*args, **kwargs):
            t0 = time.time()
            result = function(*args, **kwargs)
            t1 = time.time()
            os.system(" echo Total time running %s: %s seconds" % (function.func_name, str(t1-t0)) + " >> timecount.log")
            return result
        return function_timer
    #-----------------------------------

  • 相关阅读:
    输入挂
    最长递增子序列nlogn的做法
    lca 倍增模版
    讨厌字符串
    js的事件处理与闭包:
    http
    html的语义化
    js性能优化
    js的缓存
    字面量声明和函数式声明
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7295534.html
Copyright © 2011-2022 走看看